CSE 322 Summer 2018 Lab 7

July 17, 2018

Problem#1

Binary input

//Code
XOR BX, BX
MOV AH, 1
INT 21H
WHILE: 
CMP AL, 0DH
JE END_WHILE
AND AL, 0FH
; SUB AL, 30
SHL BX,1 
OR BL, AL
INT 21H
JMP WHILE

END_WHILE:

Problem#2

Binary output

//code
mov bx, 1010101000110011b
mov cx, 16
top:
rol bx, 1 
jc print1 
mov ah, 2
mov dl, '0'
int 21h 
jmp label

print1:
mov ah, 2
mov dl, '1'
int 21h
label: 
loop top

Problem#3 Section A (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

//Code
mov ah,1
int 21h
mov bl, al 
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h

mov bh, 0

mov cx, 8
top:
rol bl, 1 
jc print1 
mov ah, 2
mov dl, '0'
int 21h 
jmp label

print1:
mov ah, 2
mov dl, '1'
int 21h 
inc bh
label: 
loop top 
mov ah, 2
mov dl, 0dh
int 21h
mov dl, 0ah
int 21h
mov dl, bh
add dl, '0'
int 21h

Problem#3 Section B (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 0 bits In Its ASCII code.

Sample execution:
TYPE A CHARACTER: A
THE ASCII CODE OF A IN BINARY IS 01000001
THE NUMBER OF 0 BITS IS 6

//Code

To be done by students

 

Problem#4

Reversing inputs

//Code 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:
mov ah,2
pop dx
int 21h

loop print

Problem#5 Section A

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

//Code
To be done by students

Problem#5 Section B

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

//Code
To be done by students

Homeworks
HEX input output
Chapter 7 problem 9
Chapter 7 problem 10
Chapter 7 problem 11

Leave a Reply