CSE 322 Summer 2018 Lab 4

June 11, 2018

Task 1 (Example 6.4)

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
mov ax, 50

cmp ax, 0
jl negative
jg positive
je zero

negative:
mov bx, -1
jmp end_
positive:
mov bx, 1
jmp end_
zero: 
mov bx, 0

end_:

Task 2 (Example 6.5)

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

//Code
mov al, 4

mov ah, 2

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

odd: 
mov dl, 'o'
int 21h
jmp end_

even: 
mov dl, 'e'
int 21h
jmp end_
end_:

Task 3

Odd even checker upto 9 and the number has to be taken as input.

//Code

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

mov ah, 2
mov dl, '-'
int 21h 

mov al, bl 

cmp al, 0
je even
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

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

even: 
mov ah, 2 
mov dl, 'e'
int 21h
jmp end_
end_: 
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

jmp top

Task 4

Read a character, and if it’s an uppercase letter, display it.

//Code
top:
mov ah, 1
int 21h

cmp al, 'A'
jl noprint
cmp al, 'Z'
jg noprint

mov ah, 2
mov dl, al
int 21h

noprint:
jmp top

Task 5(Example 6.7)

Read a character. If it’s “y” or “Y”, display it; otherwise, terminate the program.

//Code
top:
mov ah, 1
int 21h

cmp al, 'Y'
je then
cmp al, 'y'
je then
jmp else
then:
mov ah, 2
mov dl, al
int 21h
jmp top
else:
mov ah, 4ch
int 21h

Task 6 (Example 6.9)

Write some code to count the number of charaters in an input line.

//Code
mov cx, 0
mov ah, 1
label1:
int 21h
cmp al, 0dh
je end_
inc cx
jmp label1

end_:

Task 7 (Example 6.10)

Write some code to read characters until a blank is read.

//Code
mov cx, 0
mov ah, 1
label1:
int 21h
cmp al, ' '
je end_
inc cx
jmp label1

end_:

Home work
Section 6.5

Leave a Reply