Assembly Lab-7
Assembly Lab-7
Technology
Assembly CS223, Fall 2023
Dr. Khaled Ahmed Mohamed
TA: Mayar Sayed Soliman
Assembly Lab - 9
1. Jump
1
// One-Way Selection mov ax, a
jle end_if
. . . ; if part
end_if:
{ . . . } // if part jg else_part
else . . . ; if part
else_part:
. . . ; else part
end_if:
jle end_if
cmp ax, c
jne end_if
. . . ; if part
end_if:
2
/ Short-Circuit OR mov eax, a
jg if_part
cmp eax, c
jne end_if
if_part:
. . . ; if part
end_if:
cmp eax, b
jle end_while
. . . ; while body
jmp start_while
end_while:
3
PROGRAM1
This program takes user input, checks if the entered number is divisible by 3, and
outputs a message accordingly.
pseudocode
If remainder is 0:
Display "The given number is divisible by 3"
Else:
Display "The given number is NOT divisible by 3"
End program
4
Code
org 100h ; Origin directive, specifying the starting address of the program
div bx ; Divide the content of the double-word in dx:ax by the operand (3)
msgYes:
lea dx, msg2 ; Load effective address of msg2 into register dx
mov ah, 9h ; Set interrupt code 9 (display string) into register ah
int 21h ; Call DOS interrupt to display the message
exit:
ret ; Return from the program
5
PROGRAM2
a simple program that takes two single-digit numbers as input, calculates their sum,
and then prints a message displaying the input numbers and their sum.
pseudocode
Define variables:
S1 = "THE SUM OF "
n1 = 0
S2 = " AND "
n2 = 0
S3 = " IS "
n3 = 0
S4 = " $"
End program
6
Code
.MODEL SMALL
.STACK 100H
.DATA
S1 DB 0AH,0DH,'THE SUM OF ' ; Message: "THE SUM OF "
n1 DB ? ; Variable for the first input digit
S2 DB ' AND ' ; Message: " AND "
n2 DB ? ; Variable for the second input digit
S3 DB ' IS ' ; Message: " IS "
n3 DB ? ; Variable for the sum
S4 DB ' $' ; Message: " $"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
7
MOV DL, n1
INT 21H
MAIN ENDP
END MAIN
8
Excercise 1
greater:
mov cx, 1 ; Set cx to 1
jmp end ; Unconditional jump to label 'end'
lesser:
mov cx, -1 ; Set cx to -1
jmp end ; Unconditional jump to label 'end'
equal:
mov cx, 0 ; Set cx to 0
end:
mov dx, cx ; Save cx in the dx register