CSE 322 Lab 7

March 31, 2018

Problem#1 (Chapter 8 example listing 2)

Multiplication by add and shift

//Solution

TITLE Progm
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC 
 mov ax,20h
 mov bx,30h
 CALL MULTIPLY
 MOV AH,4CH
 INT 21H
MAIN ENDP
MULTIPLY PROC
 PUSH AX
 PUSH BX
 XOR DX,DX
REPEAT:
 TEST BX,1
 JZ END_IF
 ADD DX,AX
END_IF:
 SHL AX,1
 SHR BX,1
 JNZ REPEAT
 POP BX
 POP AX
RET
MULTIPLY ENDP
END MAIN

Problem#2 (Chapter 9 program listings)

Decimal input output procedures

//Solution

.model small
.stack 100h
.code
main proc 
 
 call indec 
 push ax
 mov ah, 2
 mov dl, 0dh
 int 21h
 mov dl, 0ah
 int 21h
 pop ax
 
 ; mov ax, -135
 call outdec
 
 mov ah, 4ch
 int 21h
 main 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, 10D
 
repeat1:
 xor dx, dx
 div bx
 push dx
 inc cx
 
 or ax, ax
 jne repeat1 
 
 mov ah,2
 
print_loop:

pop dx
 or dl, 30h
 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 exit3
 
 neg ax
 
exit3:
 pop dx
 pop cx
 pop bx
 ret
 
not_digit:
 mov ah,2
 mov dl, 0ah
 int 21h
 mov dl, 0dh
 int 21h
 jmp begin 
 
 
 
indec endp
end main 

Problem#3 (Chapter 8 problem 8) //homework

Write a program that lets the user type some text, consisting of words separated by blanks, ending with a carriage return, and displays the text in the same word order as entered, but with the letters in each word reversed. For example, “this is a test” becomes “siht si a tset”. Hint: modify program PGM8_2.ASM in section 8.3.

//Solution

TO be done by students

Home work #1
Chapter 7 Problem 12
Chapter 7 Problem 13
Chapter 8 Problem 10

Leave a Reply