Professional Documents
Culture Documents
Answer
Step 1
For both the conversions, the basic algorithms remain the same
For hexa, we need to divide the number by 16, and for octal by 8, to and proceed with the
conversion
Step 2
//i) Code
.model small
.stack 100h
.data
.code
again:
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,9
int 21h
mov ah,1
int 21h
mov bl,al
jmp go
go:
cmp bl,'9'
ja hex
jb num
je num
hex:
cmp bl,'F'
ja illegal
lea dx,msg2
mov ah,9
int 21h
mov dl,49d
mov ah,2
int 21h
sub bl,17d
mov dl,bl
mov ah,2
int 21h
jmp inp
inp:
lea dx,msg3
mov ah,9
int 21h
mov ah,1
int 21h
mov cl,al
cmp cl,'y'
je again
cmp cl,'Y'
je again
jmp exit
num:
cmp bl,'0'
jb illegal
lea dx,msg2
mov ah,9
int 21h
mov dl,bl
mov ah,2
int 21h
jmp inp
illegal:
g
lea dx,msg4
mov ah,9
int 21h
mov ah,1
int 21h
mov bl,al
jmp go
exit:
Step 3
ii) code
.MODEL SMALL
.STACK 100H
.DATA
d1 dw 16
.CODE
MOV AX,
@DATA
MOV DS,
AX
in variable d1
mov ax,
d1
CALL PRINT
;interrupt to exit
; p
MOV AH,
MAIN ENDP
PRINT PROC
;initialize count
mov cx,
if
ax is zero
cmp ax,
0 je print1
;divide it by 8;
to convert it to octal
div bx
push dx
inc cx
;set dx to 0
xor dx,
dx
jmp label1
print1:
;check if count
cmp cx,
0 je exit
pop dx
;add 48 so that it
add dx,
,
48
;interrupt to print a
;character
mov ah,
dec cx
jmp print1
exit : ret
PRINT ENDP
END MAIN
upvote pl