use the 80x86, 32 bit processors. use this format the following program as a exa
ID: 3726525 • Letter: U
Question
use the 80x86, 32 bit processors. use this format the following program as a example to how to write it:
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
len DWORD ?
wid DWORD ?
hgt DWORD ?
prompt1 BYTE "Enter length: ", 0
prompt2 BYTE "Enter width: ", 0
prompt3 BYTE "Enter height: ", 0
string BYTE 40 DUP (?)
results BYTE "Surface area is", 0
area BYTE 20 DUP (?), 0
.CODE
_MainProc PROC
input prompt1, string, 40 ; read ASCII characters
atod string ; convert to integer
mov len, eax ; stores in memory 32 bits
input prompt2, string, 40 ; repeat for width
atod string
mov wid, eax ; stores in memory 32 bits
input prompt3, string, 40 ; repeat for height
atod string
mov hgt, eax ; stores in memory 32 bits
mov eax, len ;result := len
imul eax, wid ;result := len * wid
mov ebx, len ;temp := len
imul ebx, hgt ;temp := len * hgt
add eax, ebx ;result := len*wid + len * hgt
mov ebx, 0 ;temp := 0
mov ebx, wid ;temp := wid
imul ebx, hgt ;temp : = wid * hgt
add eax, ebx ;result := len*wid + len * hgt + wid * hgt
add eax, eax ;result := 2*(len*wid + len * hgt + wid * hgt)
dtoa area, eax ;convert to ASCII
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END ; end of source code
Assignment #9 Using the windows32 or windows64 framework, write an assembly program that asks the user for a positive integer value. The program should then use a loop to compute 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. Note: you need to include the source code and the output of the assignmentExplanation / Answer
C program:
#include <stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter a positive integer value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("the sum is:%d",sum);
return 0;
}
Output:
Enter a positive integer value:2
the sum is:3
Assembly program:
.LC0:
.string "Enter a positive integer value:"
.LC1:
.string "%d"
.LC2:
.string "the sum is:%d"
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-8], 0
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-12]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov DWORD PTR [rbp-4], 1
.L3:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-4], eax
jg .L2
mov eax, DWORD PTR [rbp-4]
add DWORD PTR [rbp-8], eax
add DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov eax, 0
leave
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.