Hi, I am trying to perform the calculation: y = (-7a+15)^2 where a is either a positive or negative integer. I'm having problems with moving -7 into a register in the first place, it keeps showing up as 0x00F9 = 249. I don't know if this is correct or not because our Professor informed us to simply enter a negative integer as such: #-7. The result when a=10 should be 3025. I am not getting that result. Any help is appreciated. Thank you.
Code:
YCALC mov.b R4, R11 ;use "a" as counter mov.b R4, R12 ;move multiplicand "a" into R12 mov.b #-7, R13 ;move multiplier into R13 jmp COMPARE ;jump to compare ;------------------------------------------------------------------------------- COMPARE cmp #0, R4 ;compare multiplcand to 0 jl YNEG ;if multiplicand negative, go to negative mult loop jmp YPOS ;if multiplicand positive, go to positive mult loop YNEG cmp #0, R11 ;compare 0 to counter jeq STORE ;if multiplcation finished, go to STORE add.w R12, R13 ;add R12, R13 inc R11 ;increase counter
jmp YNEG
YPOS cmp #0, R11 ;compare 0 to counter jeq STORE ;if multiplcation finished, go to STORE sub.w R12, R13 ;subtract R12, R13 dec R11 ;decrease counter
jmp YPOS STORE add.w #15, R13 ;add #15 to multiplcation result add.w R13, R13 ;perform squaring operation mov.w R13, R6 ;move final result into R6 jmp FCALC ;go to FCALC