Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to create an assembly language that takes 2 digits and convert the input in

ID: 3579676 • Letter: N

Question

Need to create an assembly language that takes 2 digits and convert the input into all bases until input-1

So if input is 10, display 10(base2), 10(base3)... 10(base9)

This is what I have so far

PAGE 55,80
.MODEL SMALL
.STACK 100H
.386
.DATA
COUNT DB 0 ; THIS IS 8 BITS VARIABLE
DIGIT1 DW ?

.CODE
MAIN PROC
MOV AX,@DATA ; SET UP DATA SEGMENT
MOV DS,AX

CALL KEYIN
MOV BL , 10
MUL BL
MOV DIGIT1, AX
CALL KEYIN
ADD DIGIT1, AX
MOV ECX, 10
MOV AX, DIGIT1

LOOP1:
MOV EDX, 0
DIV ECX
MOV EBX, EAX
PUSH DX
INC COUNT
MOV EAX, EBX
CMP EAX, 0

JNZ LOOP1

LOOP2:
POP DX
CALL DISPLAY
DEC COUNT

JNZ LOOP2

MOV AX,4C00H ; RETURN TO DOS
INT 21H


DISPLAY PROC ; DISPLAY OF A SINGLE CHARACTER
MOV AH, 6
ADD DL, 30H
INT 21H
  
RET
DISPLAY ENDP

KEYIN PROC
MOV AH, 1
INT 21H
SUB AL, 30H
MOV AH, 0

RET
KEYIN ENDP

MAIN ENDP
END MAIN

Explanation / Answer

Solution:

#Assembly code for 2 digits taken and convert the input into all bases until input-1

SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1

segment .data

msg1 db "Enter a digit ", 0xA,0xD
len1 equ $- msg1

msg2 db "Please enter a second digit", 0xA,0xD
len2 equ $- msg2

msg3 db "The sum is: "
len3 equ $- msg3

segment .bss

num1 resb 2
num2 resb 2
res resb 1

section .text
global _start ;must be declared for using gcc
  
_start: ;tell linker entry point
mov eax, SYS_WRITE   
mov ebx, STDOUT   
mov ecx, msg1   
mov edx, len1
int 0x80

mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num1
mov edx, 2
int 0x80

mov eax, SYS_WRITE
mov ebx, STDOUT   
mov ecx, msg2
mov edx, len2   
int 0x80

mov eax, SYS_READ
mov ebx, STDIN
mov ecx, num2
mov edx, 2
int 0x80

mov eax, SYS_WRITE   
mov ebx, STDOUT   
mov ecx, msg3
mov edx, len3   
int 0x80

; moving the first number to eax register and second number to ebx
; and subtracting ascii '0' to convert it into a decimal number
  
mov eax, [num1]
sub eax, '0'
  
mov ebx, [num2]
sub ebx, '0'

; add eax and ebx
add eax, ebx
; add '0' to to convert the sum from decimal to ASCII
add eax, '0'

; storing the sum in memory location res
mov [res], eax

; print the sum
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, res   
mov edx, 1
int 0x80

exit:

mov eax, SYS_EXIT   
xor ebx, ebx
int 0x80

.model small
.stack 100h
   data
   prompt db 13, 10, 'First number:','$'
   prompt db 13,10, 'Second number:', '$'
   result db 13, 10, 'Sum','$'
   ;Variables
  
   num1 db ?
   num2 db ?
   sum db ?

.code
main proc

mov ax,@data ;get data segment address
   mov ds,ax ;initialize ds

   ;Display Prompt
  
   mov ah,9 ;print string function
   mov dx,offset prompt;ds:dx points to string
   int 21h
  
   ; Numbers from the user
   mov ah,1 ;input function
   int 21h
   mov bl,al ;save the value from input
   mov num1,al
  
   mov ah,9
   lea dx, prompt ;print prompt
   int 21h
  
   mov ah,2 ;input second function
   int 21h
   mov bh,al ;save the value from second input
   mov num2,al
  
   ;Addition
   mov ax,num1 ;move num1 into ax
   add ax,num2 ;add first and second numbers together
   mov sum,ax ;move the total sum of numbers in sum
  
   ;Print Sum
   mov ah,9
   lea dx, result ; print result
   int 21h
  
   mov ah,2
   mov dl,bl
   int 21h
  
   mov dl,'+' ;display + sign
   int 21h
  
   mov dl,bh
   int 21h
  
  
   mov dl,'=' ;display = sign
   int 21h
  
   mov dl,bh
   int 21h
  
   mov ah,4ch
   int 21h

display proc ; display of a single character
   mov ah, 6
   add dl, 30h
   int 21h
  
   ret
   display endp
   keyin proc
   mov ah, 1
   int 21h
   sub al, 30h
   mov ah, 0

   ret

keyin endp

   main endp

   end main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote