Write a MASM program that computes the sum of the integers from 1 to N where N is a positive integer. Use the equal sign directive to define N. Save the sum in the EAX register. You must use loops.
For example,
1 = 1
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
Language ( Assembly)
ASAP
#INCLUDE io.h
Cr EQU 0ah
Lf EQU 0dh
data SEGMENT
p_n DB cr, lf, 'Enter n: ',0
p_num DB lf, 'Enter a number: ',0
p_sun DB cr, lf, 'The sum is: ',0
tmpstr DW 40 DUP (?)
data ENDS
code SEGMENT
ASSUME cs:code, ds:data
start: mov ax, data
mov ds, ax
output p_n
inputs tmpstr, 10
atoi tmpstr
mov dx, ax
mov bx, 0
n_ip: output p_num
inputs tmpstr, 10
atoi tmpstr
add bx, ax
dec dx
jnz n_ip
output p_sum
itoa tmpstr, bx
output tmpstr
quit: mov al, 00h
mov ah, 4ch
int 21h
code ENDS
END start
Get Answers For Free
Most questions answered within 1 hours.