CSE 322 Lab 4

February 23, 2018

Problem#1 (Eg 6.4)

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

//Solution

```mov ax, 0FFFFh
cmp ax, 0
jl negative
je zero
jg positive

negative:
mov bx, -1
mov dl, 'n'
jmp end
zero:
mov bx, 0
mov dl, 'z'
jmp end
positive:
mov bx, 1
mov dl, 'p'
jmp end
end:
mov ah, 2
int 21h```

Problem#2 (example 6.5)

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

//Solution

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

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

odd:
mov dl, 'o'
jmp end
even:
mov dl, 'e'
jmp end

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

Problem#3 (example 6.6)

Read a character and if it is uppercase display it

//Solution

```top:
mov ah, 1
int 21h

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

mov dl, al
mov ah, 2
int 21h

notPrint:

jmp top```

Problem #4 (example 6.7)

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

//Solution

```top:
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
mov ah, 1
int 21h

cmp al, 'y'
je print
cmp al, 'Y'
je print
jmp exit

print:
mov ah, 2
mov dl, al
int 21h

jmp top

exit:
```

Problem #5 (Example 6.9)

Write some code to count the number of characters In a input line.

//Solution

```mov cx, 0
mov ah, 1
while:
int 21h

cmp al, 0dh
je end_while
inc cx
jmp while

end_while:
```

Problem #6 (Example 6.10)

//Solution

```mov cx, 0
mov ah, 1
while:
int 21h

cmp al, ' '
je end_while
inc cx
jmp while

end_while:
```

Problem #7

Dispay the extended ascii characters from 80h to FFh with only 10 ascii characters per line with a space between each characters.

//Solution

```mov cl, 80h

mov ah, 2

label2:
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
mov bl, 10

label1:
mov dl, cl
int 21h
mov dl, ' '
int 21h

dec bl
inc cl
cmp cl, 0ffh
je end
cmp bl, 0
je label2
jmp label1
end:
```