CSE 322 Fall 2018 Lab 3

October 2, 2018

Problem #1

A basic while loop

//Code
label1: 
mov ah, 2
mov dl, '1'
int 21h
jmp label1

Problem #2 (Example 6.1) [If-else structure]

suppose AX aml BX contain signed numbers. Write some code to put the biggest one in cx.

//Code
mov ax, 70
mov bx, 60

cmp ax, bx
jg label1
jl label2
label1:
mov cx, ax
jmp abc
label2:
mov cx, bx 

abc:

Problem #3 (Example 6.2) [If-then structure]

Replace the number in AX by its absolute value.

//Code
mov ax, -5

cmp ax, 0
jg A1

neg ax 
A1:

Problem #4 (Example 6.3)

Suppose AL and BL contain extended ASCII characters. Display the one that comes first in the character sequence.

//Code

mov ah, 1
int 21h
mov bl, al
int 21h
mov bh, al

cmp bl, bh
jl print
jg print2
print:
mov ah, 2 
mov dl, bl
int 21h 
jmp end_
print2:
mov ah, 2
mov dl, bh
int 21h
end_:

//Alternative code
mov ah, 1
int 21h
mov bl, al
int 21h
mov bh, al

cmp bl, bh
jl print 
mov ah, 2
mov dl, bh
int 21h 
jmp end_
print:
mov ah, 2 
mov dl, bl
int 21h 
end_:

Problem #5 (Example 6.4) [Case structure]

If AX contains a negative number, put -1 In BX; if AX contains 0, put 0 In BX; if AX contains a positive number, put 1 In BX.

//Code
; ax=+ve bx=1
; ax=0 bx=0
; ax=-ve bx=-1 
mov ax, -50

cmp ax, 0
jg greater
jl less
je equal 

greater:
mov bx, 1
jmp end_
less:
mov bx, -1
jmp end_
equal:
mov bx, 0

end_:

Problem #6 (Example 6.5) [Another Case structure]

If AL contains 1 or 3, display “o”; if AL contains 2 or 4,display “e”.

//Code
mov al, 1

cmp al, 1
je odd
cmp al, 2
je even
cmp al, 3
je odd
cmp al, 4
je even

odd: 
mov ah, 2
mov dl, 'o'
int 21h
jmp end_
even: 
mov ah, 2
mov dl, 'e'
int 21h
end_:

Problem #7

Take a number from 0-9 as input and print ‘o’ if the number is odd and print ‘e’ if the number is even

//Code
top:
mov ah, 1
int 21h 
sub al, '0'

cmp al, 1
je odd
cmp al, 2
je even
cmp al, 3
je odd
cmp al, 4
je even 
cmp al, 5
je odd
cmp al, 6
je even
cmp al, 7
je odd
cmp al, 8
je even 
cmp al, 9
je odd
cmp al, 0
je even

odd: 
mov ah, 2
mov dl, 'o'
int 21h
jmp end_
even: 
mov ah, 2
mov dl, 'e'
int 21h
end_: 

mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
jmp top

Problem #8 (Example 6.8)

Print 80 stars using count controlled loop

//Code 
mov cx, 10

mov ah, 2
mov dl, '*'
top:
int 21h
loop top

Problem #9

Draw a 10*10 box of stars without using any string. Use only flow control instruction and loop to draw the box.

//Code
To be done by students

Leave a Reply