I'm trying to build a BMI calculator in Assembly. I'm pretty lost to begin with so if any of this doesn't make any sense at all I apologize in advance. I'm making it with predefined values so I don't even need to request for user input.
I'm using uVision5 and the Legacy Device is NXP, LPC2104. I think this is ARM if that's helpful.
Here is what I have so far, I'm trying to do this equation:
BMI = (weightInPounds * conversionFactor) / (heightInInches * heightInInches)
The rules are I have to have the following data definitions:
- weightInPounds DCD 150
- heightInInches DCD 64
- conversionFactor EQU 703
Here is what I have so far:
AREA File1, CODE, READONLY
ENTRY
LDR r1,weightInPounds ;loads weight into r1
LDR r2,heightInInches ;loads height into r2
LDR r3,=conversionFactor ;loads conversion into r3
MUL r4,r1,r3 ;mult weight by conv factor
MUL r5,r2,r2 ;square height
MOV r0,r5, LSR #r4 ;divide previous 2 and store in r0
stop B stop ;force infinite loop by branching to this line
weightInPounds DCD 150 ;defines weight
heightInInches DCD 64 ;defines height
conversionFactor EQU 703 ;defines conversion factor for BMI calc
END ;end of program
Here are my problems
- The line LDR r3,conversionFactor ;loads conversion into r3 doesn't work because EQU isn't the same as DCD but I don't know how to fix it and I've looked everywhere and can't figure it out.
The first MUL line doesn't work because of the previously mentioned error.
I don't know how to divide by a register... In the Line "MOV r0,r5, LSR #r4 what I'm trying to do is divide like in the equation.
Any help would be greatly appreciated.