Professional Documents
Culture Documents
Computer Organization and Assembly Language: National University of Sciences and Technology
Computer Organization and Assembly Language: National University of Sciences and Technology
Computer Organization and Assembly Language: National University of Sciences and Technology
Section: BSCS-8A
Semester: 3rd
Department of Electrical Engineering
Mehboob
Alam
Zeeshan
Azhar
Objective: The aim of this lab is to use unconditional/Conditional jumps to implement
conditional structures in Assembly language. We will also learn about analogue input and
analogue output pins of arduino.
LAB TASK 1:
Compare unsigned AX to BX, and copy the smaller of the two into a variable named smaller. Take
integer input from the user. Display the variable ‘smaller’ content.
Hint: Use call dumpmem, to display variable.
movesi, offset var
movecx ,lengthofvar
movebx , type var
call dumpmem
Answer:
Code:
INCLUDE Irvine32.inc
.data
smaller DWORD ?
.code
main proc
mov eax, 7
mov ebx, 5
cmp eax, ebx
jb smaller1
mov smaller, ebx ;smaller = ebx
jmp progmend
smaller1:
mov smaller, eax ;smaller = eax
jmp progmend
progmend:
mov esi, offset smaller
mov ecx, lengthof smaller
call dumpregs
call dumpmem
exit
main endp
END main
Output:
LAB TASK 2:
Write a code to find maximum of three numbers. Enter three numbers from the user.
Code should work on signed numbers. (For example: three numbers enter by user
can be -9, +89,+100, or -50, -3, +79, etc).
Hint: Use “call Readint” for taking integer input from user. Reads signed 32-bit decimal integer from
standard input. Call Readint, stores the value in EAX register.
Answer:
Code:
INCLUDE Irvine32.inc
.data
greater DWORD ?
num1 DWORD ?
num2 DWORD ?
num3 DWORD ?
.code
main proc
call readint
MOV num1,eax
call readint
MOV num2,eax
call readint
MOV num3,eax
mov ebx, num1
cmp ebx, num2
jg l1
mov ebx, num2
cmp ebx, num3
jg l3
mov ebx, num3
mov greater, ebx
;---------------------------
l1:
cmp ebx, num3
jg l2
;---------------------------
l2:
mov greater, ebx
;---------------------------
l3:
mov greater, ebx
mov esi, offset greater
mov ecx ,lengthof greater
mov ebx , type greater
call dumpmem
exit
main endp
END main
Output:
LAB TASK 3:
Using the following table as a guide, write an assembly program that asks the user
to enter an integer test score between 0 and 100. The program should display the
appropriate letter grade:
Code:
INCLUDE Irvine32.inc
.data
str1 BYTE "Enter an integer score: ",0
str2 BYTE "The letter grade is: ",0
.code
main PROC
call Clrscr
mov edx,OFFSET str1 ; input score from user
call WriteString
call ReadInt
call Crlf
cmp eax,60 ; I change the condition a little I don’t really like the idea
jnge l1 ; of negative score get an A
cmp eax,70
jnge l2
cmp eax,80
jnge l3
cmp eax,90
jnge l4
cmp eax,200 ; And if you get more than 200 out of 100,You probably cheat
jng l5
l1: mov al,'F'
jmp l6
l2: mov al,'D'
jmp l6
l3: mov al,'C'
jmp l6
l4: mov al,'B'
jmp l6
l5: mov al,'A'
jmp l6
l6:
mov edx,OFFSET str2
call WriteString
call WriteChar ; display grade letter in AL
call Crlf
exit
main ENDP
END main
Output:
TINKER CAD
Task 1:
Turn-off the led when we press the button and otherwise turn-on the led.
Answer:
Task 2:
Turn-on the led from minimum brightness to maximum brightness. otherwise turn-off the led from
maximum brightness to minimum brightness. Connect the led from analogue output pin. (similar
to example 2)
Answer:
Answer: