COAL Lab 7 (22k-4136)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

LAB 7 (22k-4136)

Task 1

INCLUDE Irvine32.inc

.data

arr WORD 1,2,3,4,5,6,7,8,9,10


duplicate WORD 10 DUP(?)
var WORD ?
.code
main PROC
mov esi,0
mov ecx,10
L1:

PUSH arr[esi]
POP ax
mov duplicate[esi],ax
add esi,2

Loop L1

mov ebx,TYPE duplicate


mov ecx,LENGTHOF duplicate
mov esi,OFFSET duplicate
call DumpMem
exit
main ENDP
END main
Task 2

INCLUDE Irvine32.inc

.data

number1 DWORD 23
number2 DWORD 90
number3 DWORD 44
var DWORD ?

prompt BYTE "The sum of three integers are: ",0

.code
main PROC

PUSH number1
PUSH number2
PUSH number3
mov ecx,3
L1:

POP eax
add var,eax

Loop L1
mov eax,var

mov edx,OFFSET prompt


call writestring
call WriteDEC
exit
main ENDP
END main
Task 3
INCLUDE Irvine32.inc

.data

arr1 WORD 1,2,3,4,5


arr2 WORD 10,20,30,40,50
arr3 WORD 5 DUP(?)
prompt byte "The sum of two array is: ",0
sum1 WORD ?
sum2 WORD ?

.code
main PROC

call SumOfArr1
call SumOfArr2
call SumOfArr3
exit
main ENDP

SumOfArr1 PROC

mov esi,OFFSET arr1


mov eax, 0
mov ecx, LENGTHOF arr1
L1:
add ax,[esi]
add esi,2
Loop L1
mov sum1,ax
ret
SumOfArr1 ENDP

SumOfArr2 PROC
mov esi,OFFSET arr2
mov eax, 0
mov ecx, LENGTHOF arr2
L1:
add ax,[esi]
add esi,2
Loop L1
mov sum2,ax
ret
SumOfArr2 ENDP

SumOfArr3 PROC

mov eax,0
add ax,sum1
add ax,sum2
mov edx,OFFSET prompt
call WriteString
call writeDec
call Crlf

ret
SumOfArr3 ENDP

END main

Task 4
INCLUDE Irvine32.inc

.data

prompt byte "Write the number of columns: ",0


gap byte " ",0
star byte "*",0
number DWORD ?
count DWORD ?
temp DWORD ?

.code
main PROC

mov edx,OFFSET prompt


call writeSTRING
call readDec
mov number,eax
call PrintStar
exit
main ENDP

PrintStar PROC

mov ecx,number
mov temp,1

L1:

mov count,ecx
mov ecx,number
L2:

mov edx,OFFSET gap


call WriteString

Loop L2

sub number,1
mov ecx,temp
L3:

mov edx,OFFSET star


call WriteString

Loop L3

add temp,1
call Crlf
mov ecx,count
Loop L1

ret
PrintStar ENDP

END main
Task 5
INCLUDE Irvine32.inc

.data

prompt byte "Write the number of columns: ",0


gap byte " ",0
char DWORD ?
number DWORD ?
count DWORD ?
temp DWORD ?
temp2 DWORD ?

.code
main PROC

mov edx,OFFSET prompt


call writeSTRING
call readDec
mov number,eax
call PrintAlphabets
exit
main ENDP

PrintAlphabets PROC

mov ecx,number
mov temp,1
mov char, 'A'
mov eax ,char
L1:

mov count,ecx
mov ecx,number
L2:

mov edx,OFFSET gap


call WriteString
Loop L2

sub number,1
mov ecx,temp
mov temp2,ecx

L3:

call WriteChar
add eax,1
mov edx,OFFSET gap
call WriteString

Loop L3

add temp,1
call Crlf
mov ecx,count
Loop L1

ret
PrintAlphabets ENDP

END main

Task 6
INCLUDE Irvine32.inc

.data

prompt byte "Write the number for sum: ",0


prompt2 byte "The sum is: ",0
number DWORD ?
.code
main PROC

mov edx,OFFSET prompt


call writeSTRING
call readDec
mov number,eax
call SumNumbers
exit
main ENDP

SumNumbers PROC

mov ecx,number
mov eax,0
L1:

add eax,ecx

Loop L1

mov edx,OFFSET prompt2


call writestring
call writeDec
call Crlf

ret
SumNumbers ENDP

END main

You might also like