CSE 506 LAB 9

October 19, 2017
By shp

Problem #1 (Chapter 7 problem 8)
Write a program that prompts the user to enter a character, and on subsequent lines prints its ASCII code in binary, and the number of 1 bits In Its ASCII code.
Sample execution:
TYPE A CHARACTER: A
THE ASCII CODE OF A IN BINARY IS 01000001
THE NUMBER OF l BITS IS 2

mov ah, 1
 int 21h
 mov bl, al

mov bh, 0
 mov cx, 8

mov ah, 2
 mov dl, 0Ah
 int 21h
 mov dl, 0Dh
 int 21h

start:
 ROL BL, 1
 Jc one

zero:
 mov dl, '0'
 int 21h
 jmp end_

one:
 inc bh
 mov dl, '1'
 int 21h

end_:

loop start

mov dl, 0ah
 int 21h
 mov dl, 0dh
 int 21h

add bh,'0'
 mov dl, bh
 int 21h

 

Problem#2 (Chapter 7 problem 12)
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


a db ?
 b db ?
 xor bl, bl
 mov ah, 1
 mov cx, 8

input1:
 int 21h
 cmp al, 0dh
 JE end_input1
 and al, 0Fh
 shl bl,1
 or bl, al

loop input1
 end_input1:
 mov a, bl

mov ah, 2

mov dl, 0ah
 int 21h
 mov dl, 0dh
 int 21h

mov ah, 1

mov cx, 8
 input2:
 int 21h
 cmp al, 0dh
 JE end_input2
 and al, 0fh
 shl bl,1
 or bl, al

loop input2
 end_input2:
 mov b, bl

mov bh, a
 mov bl, b

add bl, bh



mov cx, 9

mov ah, 2
 mov dl, 0Ah
 int 21h
 mov dl, 0Dh
 int 21h

start:
 ROL BL, 1
 Jc one

zero:
 mov dl, '0'
 int 21h
 jmp end_

one:
 inc bh
 mov dl, '1'
 int 21h

end_:

loop start

 

Problem#3 (Chapter 8 example)
Reversing input

mov cx, 0
 
 mov ah, 1
 int 21h
 
while: 
 cmp al, 0dh
 je end_while
 push ax
 inc cx
 int 21h
 jmp while
 
end_while:
 
 mov ah, 2 
 mov dl, 0dh
 int 21h
 mov dl, 0ah
 int 21h
print:
 pop dx
 int 21h
 loop print

 

 

Problem#4 (Chapter 8 exampel)
Multiplication by add and shift in a procedure

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

Leave a Reply