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

Write an assembly language program in a file, hw6 asm, that will add the countin

ID: 3834636 • Letter: W

Question

Write an assembly language program in a file, hw6 asm, that will add the counting numbers from 1 up to an integer that is supplied in a word in memory. So if the integer is 5, the sum would be 1 + 2 + 3 + 4 + 5 doublerightarrow 15. The result should be written to a word in memory. If the original number is negative, it should just place this negative number into memory as the result. Additionally, it should write the character + or the character - to memory based on the status of the number given. Your data segment will thus contain something like: limit dw 48 result dw ? sign db ?

Explanation / Answer

code SEGMENT

ASSUME cs:code, ds:data

start: mov ax, data

mov ds, ax;input the number

output p_num

inputs tmpstr, 10

atoi tmpstr;initialize

mov cx, 00h;stores the sum of digits

mov ten, 10;iterate to reverse digits

next: cmp ax, 0

jz op_sum;exit the loop if number=0

cwd

idiv ten;to extract units digit

add cx, dx;add the units digit

jmp next

quit: mov al, 00h

mov ah, 4ch

int 21h

code ENDS

END start

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