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

We have the following code from a previous lab: title lab5 (lab5.asm) .model sma

ID: 3566427 • Letter: W

Question

We have the following code from a previous lab:

title lab5 (lab5.asm)

.model small

.stack 100h

.data

Y dw 2000

W dw ?

Sum dw ?

printSum db "The Sum is: "   

sumMessage db 0,0,0,0,0 ,0dh, 0ah

printW db "W is: "

wMessage db 0,0,0,0,0 ,0dh, 0ah, '$'

.code

main proc

mov ax,@data

mov ds,ax

mov ax,Y ;Store Y in ax register

sub ax,1

mov Y, ax

mov ax, 0

mov Sum,36 ; add 36 to Sum

mov bx,Y

add Sum,bx ; add 36 and Y into Sum

mov ax,Y

mov bx,4 ; take Y and divide by 4

mov dx,0

idiv bx

add Sum,ax

mov ax,Y ;take Y and divide by 100

mov bx,100

mov dx,0

idiv bx

add Sum,ax

mov bx,7

mov dx,0 ; calculate W

idiv bx

mov W,dx

add W,1

mov dx, W

add dl, 30h

mov wMessage+1, dl

mov ax, 0

mov dx, 0

mov ax,Sum

mov cx, 10 ;start modding the number 2553

idiv cx   

mov si, 4

sumLoop: ;Loop to mod and store 2553 into sumMessage

   add dl, 30h

   mov sumMessage+si, dl

   mov dx, 0

   mov cx, 10

   idiv cx

   dec si   

   cmp si, 0h

   je endSum

loop sumLoop

endSum:

mov si, 0

mov cl, printSum

L1: ;Loop to print out "Sum is : 2553

   mov al, 0

   mov al, printSum[si]

   inc si

   cmp al, '$'

   je end_loop

   mov dl, al   

   mov ah, 2h

   int 21h

  

loop L1

end_loop:

mov ax,4C00h

int 21h

main endp

end main

We have to take the variable Y and have it accept user input instead of be pre-defined as 2000 as in the code above. Can you show the code needed to implement this? Thank you!

Explanation / Answer

.model small

.stack 100h

.data
string db 'Enter the value of y : $'

Y dw ?

W dw ?

Sum dw ?

printSum db "The Sum is: "

sumMessage db 0,0,0,0,0 ,0dh, 0ah

printW db "W is: "

wMessage db 0,0,0,0,0 ,0dh, 0ah, '$'

.code

main proc

mov ax,@data
mov ds,ax

mov ax,offset string
mov ah,09
int 21h

mov ah,01
mov Y,ax ;Store Y in ax register
int 21h
sub ax,1

mov Y, ax

mov ax, 0

mov Sum,36 ; add 36 to Sum

mov bx,Y

add Sum,bx ; add 36 and Y into Sum

mov ax,Y

mov bx,4 ; take Y and divide by 4

mov dx,0

idiv bx

add Sum,ax

mov ax,Y ;take Y and divide by 100

mov bx,100

mov dx,0

idiv bx

add Sum,ax

mov bx,7

mov dx,0 ; calculate W

idiv bx

mov W,dx

add W,1

mov dx, W

add dl, 30h

mov wMessage+1, dl

mov ax, 0

mov dx, 0

mov ax,Sum

mov cx, 10 ;start modding the number 2553

idiv cx

mov si, 4

sumLoop: ;Loop to mod and store 2553 into sumMessage

   add dl, 30h

   mov sumMessage+si, dl

   mov dx, 0

   mov cx, 10

   idiv cx

   dec si

   cmp si, 0h

   je endSum

loop sumLoop

endSum:

mov si, 0

mov cl, printSum

L1: ;Loop to print out "Sum is : 2553

   mov al, 0

   mov al, printSum[si]

   inc si

   cmp al, '$'

   je end_loop

   mov dl, al

   mov ah, 2h

   int 21h

loop L1

end_loop:

mov ax,4C00h

int 21h

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