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

ASSEMBLY LANGUAGE Write a program to print the sum of two digits Example run: En

ID: 3800233 • Letter: A

Question

ASSEMBLY LANGUAGE

Write a program to print the sum of two digits

Example run:

Enter first digit: 1

Enter second digit: 2

Sum = 3

I have the answer but it gets a bunch of errors! CAN SOMEONE CORRECT THIS CODE FOR ME?

.model small
.stack 100h
.data
Message1 db "Enter First Digit : $"
Message2 db, 0dh,0ah, "Enter Second Digit : $"
Message3 db , 0dh,0ah, "SUM of Entered Numbers = $"
No1 db ? ;
No2 db ?, ;
ans db ?, "$"
.code
main PROC
  
mov ax, @data ;initiaize ds
mov ds, ax
mov dx, OFFSET Message1 ;load and display msg1
mov ah, 09
int 21h
mov ah, 1h ;read first initial
int 21h
sub al, 30h
mov No1, al
mov dx,offset Message2 ;load and display msg2
mov ah, 9
int 21h
;read second initial
mov ah , 1h
int 21h
sub al, 30h
mov No2, al
mov dx,offset Message3
mov ah 9 ;load and display msg3
int 21h
mov al, No1 ;add No1 and No1
add al, No2
add al, 30h ;moves value into ans
mov ans, al
mov dx,offset ans ;load and display msg3
mov ah, 9
int 21h
;returns control to dos
mov ah, 4ch
int 21h

main endp
end main

Explanation / Answer

$LC0: .ascii "Enter First Digit:" .align 2 $LC1: .ascii "%d" .align 2 $LC2: .ascii "SUM of Entered Numbers = %d" .text .align 2 .globl _Z4testv $LFB12 = . .set nomips16 .ent _Z4testv .type _Z4testv, @function _Z4testv: .frame $sp,48,$31 # vars= 8, regs= 3/0, args= 16, gp= 8 .mask 0x80030000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-48 $LCFI0: sw $31,44($sp) $LCFI1: sw $17,40($sp) movz $31,$31,$0 $LCFI2: sw $16,36($sp) $LCFI3: .cprestore 16 lw $16,%got($LC0)($28) lw $25,%call16(printf)($28) nop jalr $25 addiu $4,$16,%lo($LC0) lw $28,16($sp) nop lw $17,%got($LC1)($28) nop addiu $4,$17,%lo($LC1) lw $25,%call16(scanf)($28) nop jalr $25 addiu $5,$sp,24 lw $28,16($sp) nop lw $25,%call16(printf)($28) nop jalr $25 addiu $4,$16,%lo($LC0) lw $28,16($sp) addiu $4,$17,%lo($LC1) lw $25,%call16(scanf)($28) nop jalr $25 addiu $5,$sp,28 lw $28,16($sp) nop lw $4,%got($LC2)($28) nop addiu $4,$4,%lo($LC2) lw $2,24($sp) lw $5,28($sp) lw $25,%call16(printf)($28) nop jalr $25 addu $5,$5,$2 lw $31,44($sp) lw $17,40($sp) lw $16,36($sp) j $31 addiu $sp,$sp,48