Write a assembly program for IA32 to count up the number of

Write a assembly program for IA-32 to count up the number of even numbers in the memory locations from 00000 to 000FF.

Solution

Answer:

Assembly Language Program :

.LC0:
.string \"count number of even digits in a given location: \"

.LC2:
.string \"Even digits: \"
main:
push rbp
mov rbp, rsp
sub rsp, 16
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], 0
.L4:
mov eax, DWORD PTR [rbp-12]
test eax, eax
jle .L2
mov ecx, DWORD PTR [rbp-12]
mov edx, 1717986919
mov eax, ecx
imul edx
sar edx, 2
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
mov DWORD PTR [rbp-8], eax
mov edx, DWORD PTR [rbp-8]
mov eax, edx
sal eax, 2
add eax, edx
add eax, eax
sub ecx, eax
mov eax, ecx
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-8]
cdq
shr edx, 31
add eax, edx
and eax, 1
sub eax, edx
cmp eax, 1
jne .L3
add DWORD PTR [rbp-4], 1
.L3:
mov ecx, DWORD PTR [rbp-12]
mov edx, 1717986919
mov eax, ecx
imul edx
sar edx, 2
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
mov DWORD PTR [rbp-12], eax
jmp .L4
.L2:
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov eax, 0
leave
ret

Write a assembly program for IA-32 to count up the number of even numbers in the memory locations from 00000 to 000FF.SolutionAnswer: Assembly Language Program
Write a assembly program for IA-32 to count up the number of even numbers in the memory locations from 00000 to 000FF.SolutionAnswer: Assembly Language Program

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site