Write an ARM Assembly program called BMICalculator that will calculate the body
ID: 3797102 • Letter: W
Question
Write an ARM Assembly program called BMICalculator that will calculate the body mass index (BMI) using weight in pounds and height in inches by evaluating the following expression, placing the result in register r0.
BMI = (weightInPounds * conversionFactor) / (heightInInches * heightInInches)
BMI = (150 * 703)/(64*64)
Your program should use the following data definitions:
weightInPounds DCD 150
heightInInches DCD 64
The EQU directive gives a symbolic name to a numeric constant. Use EQU directive to give a conversionFactor name to 703.
Syntax: name EQU expr{, type}
Example: temperature EQU 20 ; assigns the value 20 to the symbol temperature.
Use LDR instruction to load weightInPounds, heightInInches, and conversionFactor into registers r1, r2, and r3 respectively. To load heightInInches to a register using LDR is optional. There is not a divide instruction, but you can use the LSR (logical shift right) to simulate division by powers of two. Use hexadecimal calculator to verify your result.
Explanation / Answer
COde:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $703, -16(%rbp)
leaq -20(%rbp), %rdx
leaq -24(%rbp), %rax
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
movl -24(%rbp), %eax
imull -16(%rbp), %eax
movl -20(%rbp), %ecx
movl -20(%rbp), %edx
movl %edx, %esi
imull %ecx, %esi
idivl %esi
movl %eax, -12(%rbp)
movl -12(%rbp), %eax
movl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
movl $0, %eax
movq -8(%rbp), %rcx
xorq %fs:40, %rcx
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.