Lab 6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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