Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly language [3 marks each] Each part of this problem gives a pseudo-code f

ID: 3597982 • Letter: A

Question

Assembly language

[3 marks each] Each part of this problem gives a pseudo-code fragment with an if-structure, and some assumptions about its variables. Give an assembly code fragment that is equivalent to the pseudo-code. Assume that general-purpose registers eax-edx are available for any task. Pseudo-Code Assumptions a) if count > value count andvalue are 32-bit, signed integers count is in eax, and value s in memory . then count : 0 end if; b)|If a+b=c 32-bit, signed a,b and c are integers, in memory checkis in ah . then check := 'Y, else check := 'N' end if; c)| if (c- a') and (c = 1A') and (c

Explanation / Answer

Question a

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 0

mov DWORD PTR [rbp-8], 100

.L4:

cmp DWORD PTR [rbp-4], 999

jle .L2

cmp DWORD PTR [rbp-8], 0

js .L3

.L2:

mov eax, DWORD PTR [rbp-8]

add DWORD PTR [rbp-4], eax

sub DWORD PTR [rbp-8], 1

jmp .L4

.L3:

mov eax, DWORD PTR [rbp-4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, 0

leave

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 .L8

cmp DWORD PTR [rbp-8], 65535

jne .L8

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

.L8:

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

Question b

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 500

mov DWORD PTR [rbp-8], 0

.L3:

cmp DWORD PTR [rbp-8], 59

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, DWORD PTR [rbp-4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, 0

leave

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

Question c

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 0

mov DWORD PTR [rbp-8], 1

.L4:

mov eax, DWORD PTR [rbp-8]

add DWORD PTR [rbp-4], eax

add DWORD PTR [rbp-8], 1

cmp DWORD PTR [rbp-4], 5000

jg .L4

cmp DWORD PTR [rbp-8], 40

jne .L3

jmp .L4

.L3:

mov eax, DWORD PTR [rbp-4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, 0

leave

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 .L8

cmp DWORD PTR [rbp-8], 65535

jne .L8

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

.L8:

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

Question d

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 1000

mov DWORD PTR [rbp-8], 100

.L3:

cmp DWORD PTR [rbp-8], 50

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, DWORD PTR [rbp-4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char>> ::operator<<(int)

mov eax, 0

leave

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote