How can I do this program in ASSEMBLY LANGUAGE ? #include <iostream> using names
ID: 3890308 • Letter: H
Question
How can I do this program in ASSEMBLY LANGUAGE ?
#include <iostream>
using namespace std;
void main ()
{
unsigned long i1;
unsigned long i2;
unsigned long i3;
unsigned long i4;
_asm
{
}
cout << "results are " << (unsigned long) i1 << ", "
<< (unsigned long) i2 << ", "
<< (unsigned long) i3 << ", "
<< (unsigned long) i4 << endl;
}
Set i1 and i2 to each have a value of 1.
Create a loop that will do the following for each iteration of the loop:
1) Add 3 to i1 and store the result into i1;
2) Multiply i2 by 3 and store the result into i2;
Terminate the loop if either i1 becomes greater than 100 OR if both the following are true: more than 15 iterations of the loop have occurred AND i2 has reached a value of at least 999999.
After the loop terminates do the following:
1) Set i3 to the number of times through the loop
2) Set i4 to the remainder of i1 divided by i3
Explanation / Answer
section .data msg db "Results are: ",0 pri db "%d ",0 section .bss i1 resd 1 ;declaring i2 resd 1 i3 resd 1 i4 resd 1 section .text global main extern printf main: mov dword[i1],1 mov dword[i2],1 mov ecx,15 level: xor edx,edx xor eax,eax mov esi,[i1] cmp esi,97 ;Comparing if value is greater than 97 if it is then go to exit ja exit mov esi,[i2] cmp esi,999999 ;Comparing if value is greater than 97 if it is then go to exit add esi,3 mov [i1],esi ;adding three mov eax,[i2] mov ebx,3 mul ebx ;Multiplying by 3 mov [i2],eax loop level exit: xor edx,edx mov ebx,15 sub ebx,eax ;counting ilterations mov [i3],ebx mov eax,[i1] mov ebx,[i3] div ebx ;remainder mov [i4],edx push msg call printf push dword[i1] push pri call printf push dword[i2] push pri call printf push dword[i3] push pri call printf push dword[i4] push pri call printf add esp,36 ;empty stack ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.