CSE 322 Summer 2018 Lab 9

August 7, 2018

Problem 1

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

//Code

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

Problem 2

String usage (Example listings 11.1, 11.2, 11.3)

//Code 
.model small
.stack 256
.data 
str db 'Hello', , '$' 
str2 db 'This is a test$' 
str3 db 20 dup(0)
.code
main proc
mov ax, @data
mov ds, ax 
mov es, ax
lea di, str3 
call readstr
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h 
lea si, str3
call printstrrev

mov ax, 4ch
int 21h 

main endp

readstr proc
push ax
push di
cld
XOR BX, BX
mov ah, 1
int 21h
while1:
cmp al, 0dh
je endwhile1
cmp al, 8h
jne else1

dec di
dec bx
jmp read
else1:
stosb
inc bx
read:
int 21h
jmp while1 
endwhile1:
pop di
pop ax
ret 

readstr endp

printstr proc
push ax
push bx
push cx
push dx
push si
mov cx, bx
jcxz p_exit
cld
mov ah, 2
top:
lodsb
mov dl, al
int 21h
loop top
p_exit:
pop si
pop dx
pop cx
pop bx
pop ax
ret 
printstr endp

printstrrev proc
push ax
push bx
push cx
push dx
push si
mov cx, bx
jcxz p_exit2 
add si, bx 
sub si, 1
std
mov ah, 2
top2:
lodsb
mov dl, al
int 21h
loop top2
p_exit2:
pop si
pop dx
pop cx
pop bx
pop ax
ret 
printstrrev endp


end main

Homework
Chapter 10 Section 10.3
Chapter 9 Problem 9
Chapter 9 Problem 10
Chapter 9 Problem 11
Chapter 9 Problem 12
Chapter 10 Program listing 10.4

Leave a Reply