# CSE 322 Fall 2018 Lab 6

### Problem #1

Introduction to stack

//Solution
Lat sheet 4 page 1-2
//Code
.MODEL small
.STACK 4h
.DATA
.CODE
MAIN PROC
mov ax, @data
mov ds, ax

mov ax, 0f0fh
push ax
inc ax
push ax
pop bx
pop cx
pop dx
pushf

popf

ENDP MAIN
end MAIN

### Problem #2 (Section 8.2)

Write a code to take an input string and print the string in reverse.

//Solution
.MODEL small
.STACK 100h
.DATA
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
mov cx, 0
mov ah, 1
top:
int 21h
cmp al, 0dh
je end_top
push ax
inc cx
jmp top
end_top:
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
print:
pop dx
int 21h
loop print

ENDP MAIN
end MAIN

### Problem #3

Introduction to procedure

//Solution
.MODEL small
.STACK 100h
.DATA
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
mov ax, 2
mov bx, 3

call a

mov ax, 4ch
int 21h

ENDP MAIN
a proc
ret
endp a
end MAIN

### Problem #4

Write a code with a multiply procedure.

//Solution
.MODEL small
.STACK 100h
.DATA
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
mov ax, 20
mov bx, 2

call mult

mov ax, 4ch
int 21h

ENDP MAIN
mult proc
push ax
push bx
xor dx, dx
repeat:
test bx, 1
jz end_if

end_if:
shl ax, 1
shr bx, 1

jnz repeat
pop bx
pop ax

ret
mult endp

### Problem #5

//Solution
.MODEL small
.STACK 100h
.DATA
.CODE
MAIN PROC
mov ax, @data
mov ds, ax
mov ax, 20
mov bx, 2

call mult

mov ax, 4ch
int 21h

ENDP MAIN
mult proc
push ax
push bx
push cx
xor cx, cx
mov cx, bx
xor dx, dx
mult_:
loop mult_
pop cx
pop bx
pop ax
ret
mult endp
end MAIN

### Problem #6

Multiply and division instruction

//Solution
mov ax, 2
mov bx, 010ffh
mul bx
mov ax, 2
mov bx, 010ffh
imul bx

mov ax, 2
mov bx, 010ffh
div bx
mov ax, 2
mov bx, 010ffh
idiv bx

### Problem #7

Write a program that prompts the user to enter two binary numbers of up to 8 digits each, and prints their sum on the next line in binary. If the user enters an illegal character, he or she should be prompted to begin again. Each input ends with a carriage return.
Sample execution:
TYPE A BINARY NUMBER, UP TO 8 DIGITS: 11001010
TYPE A BINARY NUMBER, UP TO 8 DIGITS: 10011100
THE BINARY SUM IS 101100110

//Solution
To be done by students