Computer Organization and Assembly Language: National University of Sciences and Technology

You might also like

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

NATIONAL UNIVERSITY OF SCIENCES AND TECHNOLOGY

School of Electrical Engineering and Computer Sciences

Computer Organization and Assembly Language


Lab # 01 Programming in Assembly Language using MASM

Instructor: Mr. Taufiq Ur Rehman

Lab Incharge: Mr. Kalim Ullah

Section: BSCS-8A
Semester: 3rd
Department of Electrical Engineering

Faculty Member:____________________ Dated: ____________________

Course/Section:____________________ Semester: __________________


Computer Organization and
Assembly Language (CS235)
Lab # 7 Conditional Structure in Assembly Language and Reading
Analogue Inputs and Outputs in Arduino using Tinkercad

PLO4 PLO5 PLO8 PLO9


Name Roll Viva /Quiz/ Analysis of data Modern tool Ethics and Individual Total
number Lab in lab report 5 Usage 5 Safety and team 25
performance marks marks 5 marks work marks
5 marks 5 marks
265362
Muhammad
Abdullah

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:

Score Range Letter Grade


90 to 100 A
80 to 89 B
70 to 79 C
60 to 69 D
0 to 59 F

Add the following features to the above program;


1- Use jmp in such a way that multiple test scores can be entered. i.e., program is
continue to ask input (test marks) from the user.
2- When you press the ‘-1’, program should ended.
3- Perform range checking on the user's input: display an error message if the test
score is less than -1or greater than 100.
Answer:

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:

Task 3: (Analogue input pin, values ranges from 0 to 1023)


Use the potentiometer instead of button. Connect it with analogue input pin of arduino. Code it in
such a way that when potentiometer value is greater, lead blink with larger delay.when
potentiometer value is smaller, led blink with smaller delay.
Minimum value of potentiometer is 0, so zero delay in blinking, led fully ON.
Maximum value of potentiometer is 1023, so max delay in blinking, led fully OFF.

Answer:

Connection with one of


the analogue pin

You might also like