0% found this document useful (0 votes)
9 views12 pages

Lab 6

Uploaded by

k230534
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Lab 6

Uploaded by

k230534
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Question 1:

Code:

INCLUDE Irvine32.inc

.data

fib DWORD 0, 1

count DWORD 10

.code

main PROC

mov eax, 0

mov ebx, 1

mov ecx, 2

call WriteDec

call Crlf

call WriteDec

call Crlf

FibonacciLoop:

mov edx, eax

add eax, ebx

mov ebx, edx

call WriteDec

call Crlf

inc ecx
cmp ecx, count

jl FibonacciLoop

exit

main ENDP

END main

Output:

Task3:

INCLUDE Irvine32.inc

.data

employeeCount DWORD 5

employeeID DWORD 5 DUP(0)

employeeName BYTE 30 * 5 DUP(0)

yearOfBirth DWORD 5 DUP(0)

annualSalary DWORD 5 DUP(0)

totalSalary DWORD 0

promptID BYTE "Enter Employee ID: ", 0

promptName BYTE "Enter Name: ", 0

promptYear BYTE "Enter Year of Birth: ", 0


promptSalary BYTE "Enter Annual Salary: ", 0

outputMsg BYTE "Total Annual Salary: ", 0

newline BYTE 10, 0

.code

main PROC

mov ecx, 0

inputLoop:

cmp ecx, employeeCount

jge calculateTotal

mov edx, OFFSET promptID

call WriteString

call ReadInt

mov employeeID[ecx * 4], eax

mov edx, OFFSET promptName

call WriteString

mov edx, OFFSET employeeName[ecx * 30]

call ReadString

mov edx, OFFSET promptYear

call WriteString

call ReadInt

mov yearOfBirth[ecx * 4], eax


mov edx, OFFSET promptSalary

call WriteString

call ReadInt

mov annualSalary[ecx * 4], eax

inc ecx

jmp inputLoop

calculateTotal:

mov ecx, 0

xor eax, eax

salaryLoop:

cmp ecx, employeeCount

jge done

add eax, annualSalary[ecx * 4]

inc ecx

jmp salaryLoop

done:

mov totalSalary, eax

mov edx, OFFSET newline

call WriteString

mov edx, OFFSET outputMsg

call WriteString

mov eax, totalSalary


call WriteDec

call Crlf

exit

main ENDP

END main

Output:
Task 4:

INCLUDE Irvine32.inc

.data

Source BYTE "Hello, World!", 0

Target BYTE 20 DUP(0)

.code

main PROC

mov esi, OFFSET Source

mov edi, OFFSET Target

mov ecx, 0

copyLoop:

mov al, [esi + ecx]

mov [edi + ecx], al

test al, al

jz done

inc ecx

jmp copyLoop

done:

mov edx, OFFSET Target

call WriteString
exit

main ENDP

END main

Output:
Task 5:

INCLUDE Irvine32.inc

.data

array DWORD 1, 2, 3, 4, 5

arraySize DWORD LENGTHOF array

.code

main PROC

mov ecx, arraySize

shr ecx, 1

mov esi, OFFSET array

mov edi, OFFSET array

add edi, arraySize * TYPE array

sub edi, TYPE array

reverseLoop:

cmp ecx, 0

jle done

mov eax, [esi]

mov ebx, [edi]

mov [esi], ebx


mov [edi], eax

add esi, TYPE array

sub edi, TYPE array

dec ecx

jmp reverseLoop

done:

mov edx, OFFSET array

call WriteInt

call Crlf

exit

main ENDP

END main

Output:
Tas6 :

INCLUDE Irvine32.inc

.data

array DWORD 8, 5, 1, 2, 6

arraySize DWORD LENGTHOF array

.code

main PROC

mov ecx, arraySize

outerLoop:

dec ecx

mov ebx, 0

mov edx, arraySize

innerLoop:

mov eax, [array + ebx * TYPE array]

mov esi, [array + ebx + TYPE array]

cmp eax, esi

jbe skipSwap
mov [array + ebx * TYPE array], esi

mov [array + ebx + TYPE array], eax

skipSwap:

inc ebx

cmp ebx, edx

jl innerLoop

cmp ecx, 0

jg outerLoop

mov edx, OFFSET array

call WriteInt

call Crlf

exit

main ENDP

END main

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy