Sunday 15 June 2014

Easy68K IF-ELSE branching -



Easy68K IF-ELSE branching -

writing first assembly language programme class using easy68k.

i'm using if-else branching replicate code:

if (p > 12) p = p * 8 + 3 else p = p - q print p

but think have branches wrong because without first halt in code programme runs through if branch anyway after cmp finds case p < 12. missing here or accepted way of doing this?

here assembly code:

start: org $1000 ; programme starts @ loc $1000 move p, d1 ; [d1] <- p move q, d2 ; [d2] <- q * programme code here cmp #12, d1 ; p > 12? bgt if ; sub d2, d1 ; p = p - q move #3, d0 ; assign read command trap #15 ; simhalt ; halt simulator if asl #3, d1 ; p = p * 8 add together #3, d1 ; p = p + 3 endif move #3, d0 ; assign read command trap #15 ; simhalt ; halt simulator * info , variables org $2000 ; info starts @ loc $2000 p dc.w 5 ; q dc.w 7 ; end start ; lastly line of source

to if..else, need 2 jumps; 1 @ start, , 1 @ end of first block.

while doesn't impact correctness, conventional retain source order, means negating condition.

move p, d1 ; [d1] <- p move q, d2 ; [d2] <- q * programme code here cmp #12, d1 ; p > 12? ble else ; p <= 12 if asl #3, d1 ; p = p * 8 add together #3, d1 ; p = p + 3 bra endif else sub d2, d1 ; p = p - q endif move #3, d0 ; assign read command trap #15 ; simhalt ; halt simulator

easy68k

No comments:

Post a Comment