HCS12 Assembly Arithmetic -
so learning assembly hcs12 microcontroller.
i need evaluate expression -45+6+(13*2)-(7*4)-65+33
. expression needs evaluated left right, following standard order of operations. each operation needs performed on byte values, , can use addition, subtraction, , shifts.
i can evaluate -45+6+(13*2)-(7*4)
fine, problems arise when try subtract 65 -41. understand what's going on, don't know how work around it.
edit: should more clear, know happening (the values being truncated). don't know why.
edit2: solved! line ldab #term5
should ldab term5
(same thing next line)
here's code i'm using, reference:
; local defines term3: equ 13 term4: equ 07 ;******************************************************************** myconst: section ; place constant data here constdata: dc.b -45,16 term5: dc.b 65 term6: dc.b 33 ;******************************************************************** mycode: section main: entry: lds #__seg_end_sstack ; initialize stack pointer sei ; disable interrupts ; program code goes here main_loop: nop ldx #constdata ; load -45 , 16 x ldaa 0,x ; load -45 x ldab 1,x ; load 16 x b aba ; add b (a=(-39)) ldab #term3 ; load 13 b aslb ; shift b left (multiply 2) aba ; add b (a=(-13)) ldab #term4 ; load 7 b aslb ; shift b left (multiply 2) asl ; shift b left (multiply 2) sba ; subtract b (a=(-41)) ldab #term5 ; issues start here. subb #term6 aba nop end ;********************************************************************
(self-answered question.)
per comments:
figured out! turns out when loading constants, don't need
#
sign.ldab #term5
shouldldab term5
. – dfryer1193 sep 3 '13 @ 16:32
Comments
Post a Comment