1. Write the Assembly code fragment to implement each of the given pseudo-code.
ID: 3805786 • Letter: 1
Question
1. Write the Assembly code fragment to implement each of the given pseudo-code.
a. Sum = 0;
For count = -10 to 50
{ add count to Sum;}
b. Sum = 1000
For count = 100 downto 50
{subtract 2*count from Sum;}
c. Count = 0;
Sum = 500; While (Count <=60) and (Sum > 200) {subtract Count from Sum; Add 5 to Count}
2. Write the assembly code fragment to implement each given pseudo-code
a. if (ch > ‘a’) and (ch <= ‘z’) {add 1 to lowerCount;} Else { if (ch > ‘A’ and (ch <’Z’) {add 1 to upperCount;} Else {add 1 to otherCount;}}
b. If (value < 500) or (count < 10) {add 10*count to value;} Else {value = 80; Subtract 1 from count;}
3. Write an interactive application that performs the following function: Repeatedly ask the user for a positive integer less than or equal to 100, until the user enters 0 or a negative number. Then display the product of the positive numbers entered by the user.
Explanation / Answer
1.a)
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], -10
.L3:
cmp DWORD PTR [rbp-8], 50
jg .L2
mov eax, DWORD PTR [rbp-8]
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L7:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
------------------------------------------------------------------------------------------------------------
1.b)
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 1000
mov DWORD PTR [rbp-8], 100
.L3:
cmp DWORD PTR [rbp-8], 49
jle .L2
mov eax, DWORD PTR [rbp-8]
add eax, eax
sub DWORD PTR [rbp-4], eax
sub DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L7:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
------------------------------------------------------------------------------------------------------------
1.c)
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 500
.L3:
cmp DWORD PTR [rbp-8], 60
jg .L2
cmp DWORD PTR [rbp-4], 200
jle .L2
mov eax, DWORD PTR [rbp-8]
sub DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 5
jmp .L3
.L2:
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L7:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.