Suppose we have the following C++ program: progz.cpp 1 #include 2 using namespace std; 3 4 5 int main() 6Ę {

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Suppose we have the following C++ program: progz.cpp 1 #include 2 using namespace std; 3 4 5 int main() 6Ę {

Post by answerhappygod »

Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 1
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 1 (127.11 KiB) Viewed 22 times
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 2
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 2 (23.08 KiB) Viewed 22 times
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 3
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 3 (45.8 KiB) Viewed 22 times
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 4
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 4 (105.14 KiB) Viewed 22 times
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 5
Suppose We Have The Following C Program Progz Cpp 1 Include Iostream 2 Using Namespace Std 3 4 5 Int Main 6e 5 (71.43 KiB) Viewed 22 times
Please answer in x86 programming language, using only the add
instruction.
; Program template
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
A DWORD ?
B DWORD 1
C1 DWORD 2 ; C is a reserved word
D DWORD 3
E DWORD 4
F DWORD 5
G DWORD 6
H DWORD 7
I DWORD 8
J DWORD 9
K DWORD 10
L DWORD 11
M DWORD 12
N DWORD 13
O DWORD 14
P DWORD 15
.code
main proc

mov eax, 0 ; initialize eax to 0
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=12
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=60
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=360
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=2520
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=20,160
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=181,440
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov ebx, eax ; ebx=1,814,400
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
; INSERT ADD INSTRUCTIONS HERE
mov A, eax
invoke ExitProcess,0
main endp
end main
edit: I added more info
Suppose we have the following C++ program: progz.cpp 1 #include <iostream> 2 using namespace std; 3 4 5 int main() 6Ę { 7 int b=1, c=2, d=3, e=4, f=5, g=6, h=7, i=8, j=9, k=10, l=11, m=12, n=13, o=14, p=15; 8 9 int a = b + c + d*e*f*g*h*i*j*k* 1 + m + n + 0 + pj 11 cout<<a<<endl<<endl; system("PAUSE"); return; 10 12 13 14 15 16 17 19 } For your second programming problem, you will be implementing the above program in x86 assembly language with the following constraint: the only instruction that can be used is the add instruction As with the first problem, the idea is that you will be representing all multiplications as repeated additions.

The idea is that multiplication is really just repeated addition. For example, 5*4 can be represented as either 5+5+5+5 or 4+4+4+4+4. The former is the more ideal representation, as it requires less addition operations to be performed. In other words, the larger number should be added to itself the shorter number of times.

Insert all of your add instructions in-between all of the mov instructions. You should have approximately ~58 add instructions in total. You will need to use two registers for this problem: eax and ebx The operands for all add instructions should be registers (EAX or EBX) or variables from the data segment. Examples: add eax, B and add eax, ebx

After you execute the ~58 add instructions, your registers should look something like this: Registers EAX = 13882B9 EBX = 2018AF80 ECX = 29401005 EDX = 28401005 ESI = 20401005 EDI = 88481005 EIP = 88401066 ESP = 8019FF84 EBP = 8019FF94 EFL = 29800212 ex00404900 = 00000000 Autos Locals Registers Threads Modules Watch 1 Call Stack Breakpoints Exception Settings Output Error List In particular, the register EAX should be storing the 32-bit hex value 01308AB9, which is 19,958,457 decimal (166 + 165*3 + 163*8 + 162*10 + 16*11 + 9 = 19,958,457)

Watch 1 Name GA Value 0.001308ab9 OX Type unsigned Autos Locals Registers Threads Modules Watch 1 Call Stack Breakpoints Exception Settings Output Error List Memory location A should now also be storing 01308AB9, because the mov A, eax instruction at the very end of the program copies the contents of register eax into the memory location represented by the variable A.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply