Debug Team Data Lake Tools Test Analyze Window Help DebugWin32 Local Windows Deb
ID: 2293780 • Letter: D
Question
Debug Team Data Lake Tools Test Analyze Window Help DebugWin32 Local Windows Debugger main.asm x (main.asm) 1 TITLE MASM Template 2 3 // Description: 5 // Revision date: 7 INCLUDE Irvine32.ind 8 .data 9 10 .code 11 main PROC 12 call Clrscr mov ebx, 50 mov eax, ebx call WriteDec call Crlf Clear screen ; move 50 into beb:x ; move ebx int eax ; write value of eax to screen ; Write a linefeed to screen 13 14 15 16 17 18 19 20 Write 55 in binary to the screen ; 32 in hex to the screen ; 20 in octal to the screern 21 23 24 25 main ENDP 26 27 exit 06 03 06 37Explanation / Answer
Code for Program to convert decimal number to binary in Assembly Language
DIS MACRO STR
MOV AH,09H
LEA DX,STR
INT 21H
ENDM
DATA SEGMENT
MSG2 DB "BINARY NUMBER IS : $"
STR1 DB 20 DUP('$')
STR2 DB 20 DUP('$')
NO DW 100
LINE DB 10,13,'$'
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,STR1
MOV AX,NO
MOV BH,00
MOV BL,2
L1:DIV BL
ADD AH,'0'
MOV BYTE PTR[SI],AH
MOV AH,00
INC SI
INC BH
CMP AL,00
JNE L1
MOV CL,BH
LEA SI,STR1
LEA DI,STR2
MOV CH,00
ADD SI,CX
DEC SI
L2:MOV AH,BYTE PTR[SI]
MOV BYTE PTR[DI],AH
DEC SI
INC DI
LOOP L2
DIS LINE
DIS MSG2
DIS STR2
MOV AH,4CH
INT 21H
CODE ENDS
END START
;------
;OUTPUT
;------
BINARY NUMBER IS : 1100100
Code for Program to Convert Decimal number to Hexadecimal number in Assembly Language
prnstr macro msg
mov ah, 09h
lea dx, msg
int 21h
endm
data segment
buf1 db "Enter a decimal number : $"
buf2 db 0ah, "Invalid Decimal Number...$"
buf3 db 0ah, "Equivalent hexadecimal number is : $"
buf4 db 6
db 0
db 6 dup(0)
multiplier db 0ah
data ends
code segment
assume cs:code, ds:data
start :
mov ax, data
mov ds, ax
mov es, ax
prnstr buf1
mov ah, 0ah
lea dx, buf4
int 21h
mov si, offset buf4 + 2
mov cl, byte ptr [si-1]
mov ch, 00h
subtract :
mov al, byte ptr [si]
cmp al, 30h
jnb cont1
prnstr buf2
jmp stop
cont1 :
cmp al, 3ah
jb cont2
prnstr buf2
jmp stop
cont2 :
sub al, 30h
mov byte ptr [si], al
inc si
loop subtract
mov si, offset buf4 + 2
mov cl, byte ptr [si-1]
mov ch, 00h
mov ax, 0000h
calc :
mul multiplier
mov bl, byte ptr [si]
mov bh, 00h
add ax, bx
inc si
loop calc
mov si, offset buf4 + 2
mov bx, ax
mov dx, 0000h
mov ax, 1000h
convert :
mov cx, 0000h
conv :
cmp bx, ax
jb cont3
sub bx, ax
inc cx
jmp conv
cont3 :
cmp cx, 0ah
jb cont4
add cl, 37h
jmp cont5
cont4 :
add cl, 30h
cont5 :
mov byte ptr [si], cl
inc si
mov cx, 0010h
div cx
cmp ax, 0000h
jnz convert
mov byte ptr [si], '$'
prnstr buf3
prnstr buf4+2
stop :
mov ax, 4c00h
int 21h
code ends
end start
Code for Program to Convert Decimal number to Octal number in Assembly Language
prnstr macro msg
mov ah, 09h
lea dx, msg
int 21h
endm
data segment
buf1 db "Enter a decimal number : $"
buf2 db 0ah, "Invalid Decimal Number...$"
buf3 db 0ah, "Equivalent octal number is : $"
buf4 db 6
db 0
db 6 dup(0)
multiplier db 0ah
data ends
code segment
assume cs:code, ds:data
start :
mov ax, data
mov ds, ax
mov es, ax
prnstr buf1
mov ah, 0ah
lea dx, buf4
int 21h
mov si, offset buf4 + 2
mov cl, byte ptr [si-1]
mov ch, 00h
subtract :
mov al, byte ptr [si]
cmp al, 30h
jnb cont1
prnstr buf2
jmp stop
cont1 :
cmp al, 3ah
jb cont2
prnstr buf2
jmp stop
cont2 :
sub al, 30h
mov byte ptr [si], al
inc si
loop subtract
mov si, offset buf4 + 2
mov cl, byte ptr [si-1]
mov ch, 00h
mov ax, 0000h
calc :
mul multiplier
mov bl, byte ptr [si]
mov bh, 00h
add ax, bx
inc si
loop calc
mov si, offset buf4 + 2
mov bx, ax
mov dx, 0000h
mov ax, 8000h
convert :
mov cx, 0000h
conv :
cmp bx, ax
jb cont3
sub bx, ax
inc cx
jmp conv
cont3 :
add cl, 30h
mov byte ptr [si], cl
inc si
mov cx, 0008h
div cx
cmp ax, 0000h
jnz convert
mov byte ptr [si], '$'
prnstr buf3
prnstr buf4+2
stop :
mov ax, 4c00h
int 21h
code ends
end start
assembly program to convert decimal to radixx
.model small
.386
.stack 100h
.data
.code
decimal proc near
;print out number given in AX in decimal
xor eax,eax
xor ebx,ebx
mov cx,2 ;this is to accept the base and the decimal value
newchar:
cmp cx,0
jle startConvert
dec cx
mov ah,1 ;This sets up to accept another input from keyboard
int 21h ;this asks for an input and stores it in al
;mov al,0h ;This sets up to accept another input from keyboard
;int 21h ;this asks for an input and stores it in al
;push ax ;stores the second input from keyboard
sub al,30h
jl stloop ;jumps if negative
cmp al,9h
jg stloop ;jumps if greater than
xor ah,ah ;to get only the digit they type
push ax ;this stores the first input from the keyboard
cbw ;convert byte to word
;jmp newchar ;to accept multiple digits
stloop:
mov ah,2
mov dl,0ah
int 21h ;This section inserts a carrige return
mov dl,0dh
int 21h
startConvert: pop bx
push ax ;given to routine to print out
;push bx
push cx
push dx
mov cx,0 ;starts a counter for the number of digits
;mov bx,10 ;base 10 conversion THIS IS THE LINE TO CHANGE FOR DIFFERENT BASES!!!!
nonzero:
xor dx,dx ;same as mov dx,0
div bx
push dx ;this is the remainder of the divider
inc cx ;this will help determine the number of digits produced
or ax,ax ;sets flags to check is ax = 0
jne nonzero ;jump not equal to
write:
pop dx ;gets deciaml digit from stack
add dl,'0' ;ascii value of 30h THIS ALSO NEEDS TO CHANGES FOR DIFFERENT BASES!!!
mov ah,2
int 21h
loop write ;loops number of times in cx, which is the number of digits
pop dx
pop cx
pop bx
pop ax
ret
decimal endp
end decimal
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.