CSE 322 Fall 2018 Lab 7

      No Comments on CSE 322 Fall 2018 Lab 7

Problem #1 (Program listing 9.2, 9.3, 9.4)

Decimal input output procedure

//Solution
.MODEL small
.STACK 256
.DATA

.CODE
MAIN PROC
mov ax,@data 
mov ds,ax 

call indec
push ax
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
pop ax

call outdec



Exit: 
mov ah,4Ch 
int 21h 
MAIN ENDP

outdec proc
push ax
push bx
push cx
push dx

or ax, ax ;Check if ax is 0
jge @end_if1

push ax
mov dl, '-'
mov ah, 2
int 21h
pop ax
neg ax
@end_if1:

xor cx, cx
mov bx, 10
@repeat1: 
xor dx, dx
div bx
push dx
inc cx

cmp ax, 0
jne @repeat1

mov ah, 2
@print_loop:
pop dx
add dl, '0'
int 21h
loop @print_loop 

pop dx
pop cx
pop bx
pop ax
ret 
outdec endp

indec proc
push bx
push cx
push dx

@begin:
mov ah, 2
mov dl, '?'
int 21h

xor bx, bx
xor cx, cx

mov ah, 1
int 21h

cmp al, '-'
je @minus
cmp al, '+'
je @plus
jmp @repeat2
@minus:
mov cx, 1
@plus:
int 21h
@repeat2:
cmp al, '0'
jnge @not_digit
cmp al, '9'
jnle @not_digit

and ax, 000Fh
push ax

mov ax, 10
mul bx
pop bx
add bx, ax

mov ah, 1
int 21h
cmp al, 0dh
jne @repeat2

mov ax, bx
or cx, cx
je @exit
neg ax
@exit:
pop dx
pop cx
pop bx
ret

@not_digit:
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
jmp @begin 
indec endp
END MAIN

Problem #2 (Section 8.2)

take 2 decimal numbers greater than 10 as inputs and print their sum and difference afterward

Sample execution
?120
?15
Sum is 135
Difference is 105

//Solution
to be done by students

Problem #3

Write a procedure to find the factorial of a number stored in cx.

//Solution
.model small
.stack 256
.data
.code

main proc
mov ax, @data
mov ds, ax

mov cx, 4
call fact 
call outdec
exit:
mov ah, 4ch
int 21h 

main endp

fact proc
mov ax, 1
loop1:
mul cx
loop loop1 
ret 
fact endp

outdec proc
push ax
push bx
push cx
push dx

or ax, ax 
jge @end_if1

push ax
mov dl, '-'
mov ah, 2
int 21h
pop ax
neg ax
@end_if1:

xor cx, cx
mov bx, 10
@repeat1: 
xor dx, dx
div bx
push dx
inc cx

cmp ax, 0
jne @repeat1

mov ah, 2
@print_loop:
pop dx
add dl, '0'
int 21h
loop @print_loop 

pop dx
pop cx
pop bx
pop ax
ret 
outdec endp
end main

Homework
1. Add hex input output and binary input output procedure to the decimal input out put procedure and do the following tasks.
a. put the last 5 digit of your registration number in ax (Treat the number as decimal) and print their equivalent binary and hexadecimal number.
b. put the last 5 digit of your registration number in ax (Treat the number as hexadecimal) and print their equivalent binary and decimal number.
c. put 100010101010 in ax and print the equivalent decimal and hexadecimal number.
d. take hexadecimal input, binary input, decimal input

2. Lab task 2
3. Chapter 8 problem 8
4. Chapter 8 problem 10

Submit your homework through this link

Leave a Reply

Your email address will not be published. Required fields are marked *