Vous êtes sur la page 1sur 8

National University of Sciences & Technology (NUST)

School of Electrical Engineering and Computer Science (SEECS)


Department of Electrical Engineering

Faculty Member:__Dr. Saad Bin Qaiser_ Dated: ___4th March, 2017______

Semester:___4th_______ Section: ___BEE-7D__________

EE-222: Microprocessor Systems

Lab 6: Writing Assembly Programs

Name Reg. No. Report Viva Total/15


Marks / 10 Marks / 5

Abdul Ahad Saeed 146583

Hamza Masood Bajwa 125839

Muhammad bin Aamir 133888

EE- 222: Microprocessor Systems Page 1


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

Lab 6: Writing Assembly Programs

Write an assembly program that takes two WORD sized arrays of first 20 even and
first 20 odd numbers (arrayE and arrayO) from the user and display them on the
screen. Place the arrayO in stack. Now write two proceduresarraySum and
arraySub that add (arrayO[stack]+arrayE[mem]) and subtract(arrayO[stack]-
arrayE[mem]) the two arrays. Display your results on screen using the strings
"sum of two arrays" and "difference of two arrays".
[10 marks]

Note: viva will be taken at the end of lab carrying 5 marks

include irvine32.inc
.data
arrayO WORD 20 DUP(?)
arrayE WORD 20 DUP(?)

prompt1 BYTE 'Enter Even Numbers',0


prompt2 BYTE 'Enter Odd Numbers',0
prompt3 BYTE 'Sum of first 20 even numbers and odd numbers:',0
prompt4 Byte 'Differnce of first 20 even numbers and odd numbers:',0
.code
main proc

mov edx,offset prompt1


call writestring
call crlf

mov ecx,lengthof arrayE


mov ebx,offset arrayE

l1:
mov ax,0
EE- 222: Microprocessor Systems Page 2
National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

call readint
mov [ebx],ax
add ebx,2
loop l1

mov ecx, lengthof arrayE


mov edx, offset arrayE
mov eax,0
l3:
mov ax, [edx]
call writeint
add edx,2
loop l3

mov edx,offset prompt2


call writestring
call crlf

mov ecx,lengthof arrayO


mov ebx,offset arrayO

l2:
mov eax,0
call readint
mov [ebx],eax
add ebx,2
loop l2

mov ecx, lengthof arrayO


mov edx, offset arrayO
mov eax,0

l4:
mov ax,[edx]
call writeint

EE- 222: Microprocessor Systems Page 3


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

add edx,2
loop l4

mov esi, OFFSET arrayO


mov edi, OFFSET arrayE
mov ecx,20

call arrayS

mov esi, OFFSET arrayO


mov edi, OFFSET arrayE

mov ecx,20
call arraySb

exit
main endp

arrayS PROC
mov edx,offset prompt3
call writestring
call crlf
mov ecx,20
add esi,19*2

Pushloop1:
mov ax,[esi]
push eax
sub esi,2
loop pushloop1

mov cl,20
additionLoop:
pop eax
add ax, [edi]

EE- 222: Microprocessor Systems Page 4


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

call writeDec
call crlf
add edi, 2
loop additionLoop

ret
arrayS ENDP

arraySb PROC
mov edx,offset prompt4
call writestring
call crlf

add esi,19*2
mov cl,20
Pushloop2:
mov ax,[esi]
push eax
sub esi,2
loop pushloop2

mov cl,20
subLoop:
pop eax
sub ax, [edi]

.if(ax > 8000h)


mov bx, 0FFFFh
sub bx, ax
xchg bx, ax
.endif

call writeDec
call crlf

EE- 222: Microprocessor Systems Page 5


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

add edi, 2
loop subLoop

ret
arraySb ENDP

end main

OUTPUT:

EE- 222: Microprocessor Systems Page 6


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

EE- 222: Microprocessor Systems Page 7


National University of Sciences & Technology (NUST)
School of Electrical Engineering and Computer Science (SEECS)
Department of Electrical Engineering

CONCLUSION
The purpose of the lab was to learn how to make and use procedures as well
as reinforce the concepts of array manipulation. Learning to use Stack
memory and push/pop was also part of the lab. We have learned how
procedures are made and implemented in this lab, as well as how to use the
stack based commands.

EE- 222: Microprocessor Systems Page 8

Vous aimerez peut-être aussi