Question

Write a MASM program that computes the sum of the integers from 1 to N where...

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

Homework Answers

Answer #1

#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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
Assembly Language Programming Write a complete assembly program that inputs a small signed integer n, whose...
Assembly Language Programming Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6. (This is not C++ or Java. Has to be masm file)
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
Write Java program Lab42.java which takes as input two positive integers m and n and computes...
Write Java program Lab42.java which takes as input two positive integers m and n and computes their least common multiple by calling method lcm(m,n), which in turn calls recursive method gcd(m,n) computing the greatest common divisor of m and n. Recall, that lcm(m,n) can be defined as quotient of m * n and gcd(m,n).
How to write a C++ program. Additive persistence is a property of the sum of the...
How to write a C++ program. Additive persistence is a property of the sum of the digits of an integer. The sum of the digits is found, and then the summation of digits is performed creating a new sum. This process repeats until a single integer digit is reached. Consider the following example: 1. The beginning integer is 1234 2. Sum its digits is 1+2+3+4 = 10 3. The integer is now 10 4. The sum of its digits is...
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
IN C LANGUAGE This program initially reads two integers from standard input: (1) an integer T...
IN C LANGUAGE This program initially reads two integers from standard input: (1) an integer T and (2) a positive integer N. It then reads N integers and counts the numbers that are greater than T and the numbers than are less than T. It then prints out these two counts. Example What is the threshold value? 7 How many values? 5 Enter 5 values: 6 7 9 9 8 3 values are greater than 7 1 values are less...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum of the digits of n. Use the following main function to test your code: int main() { int n, sn; cout << "Enter q to quit or an integer: "; while ( cin >> n ) { sn = sumofdigits(n); cout << "sumofdigits( " << n << " ) = " << sn; cout << "\nEnter q to quit or an integer: "; }...
How many ways are there to represent a positive integer n as a sum of (a)...
How many ways are there to represent a positive integer n as a sum of (a) k non-negative integers? (b) k positive integers? Note: the order of summation matters. For example, take n = 3, k = 2. Then the possible sums in (a) are 3+0, 2+1, 1+2, 0+3
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...