In: Computer Science
In 80X86 assembly language
Calories Burned
Running on a particular treadmill, you burn 4 calories per minute.
Write a program that uses a loop to display the number of calories
burned after 5, 10, 15, 20, 25, and 30 minutes
pls show input and output
C code :
#include <stdio.h>
int main()
{
const float CALORIES_BURNED_PER_MIN = 3.6;
float calories_burned = 0;
for (int i = 5; i <= 30; i += 5)
{
calories_burned = (i * CALORIES_BURNED_PER_MIN);
printf("calories burned after %d minutes =
%d\n",i,calories_burned);
}
return 0;
}
Assembly 8086 code :
.LC2:
.string "calories burned after %d minutes = %d\n"
main:
push rbp
mov rbp, rsp
sub rsp, 16
movss xmm0, DWORD PTR .LC0[rip]
movss DWORD PTR [rbp-8], xmm0
pxor xmm0, xmm0
movss DWORD PTR [rbp-12], xmm0
mov DWORD PTR [rbp-4], 5
jmp .L2
.L3:
pxor xmm0, xmm0
cvtsi2ss xmm0, DWORD PTR [rbp-4]
movss xmm1, DWORD PTR [rbp-8]
mulss xmm0, xmm1
movss DWORD PTR [rbp-12], xmm0
pxor xmm2, xmm2
cvtss2sd xmm2, DWORD PTR [rbp-12]
movq rdx, xmm2
mov eax, DWORD PTR [rbp-4]
movq xmm0, rdx
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 1
call printf
add DWORD PTR [rbp-4], 5
.L2:
cmp DWORD PTR [rbp-4], 30
jle .L3
mov eax, 0
leave
ret
.LC0:
.long 1080452710