#------------------------------------------------------------------------------- # Thomas C. Bressoud # 29 January 2006 # ifthen.s # # Description: Program to demonstrate an assembly translation of an if-then # construct. #------------------------------------------------------------------------------- # Next directive defines additions to the data segment .data .align 2 ; Start on 4 byte boundary A: .long 23 ; Allocate a 4 byte data word B: .long 17 ; Allocate another 4 byte data word ifmsg: .asciz "Message when the if-block evaluates to true\n" endmsg: .asciz "At code following the if-block\n" # Next directive defines additions to the text (code) segment .text .align 2 ; Start on a 4 byte boundary .globl _main ; Make the _main symbol visible outside this module _main: mflr r0 ; Put the return address from main into r0 stw r0,8(r1) ; Save in the linkage of the callers stack frame stwu r1,-32(r1) ; Allocate a new stack frame, updating the stack ptr ; if (A > B) { ; print_string(ifmsg); ; } ; print_string(endmsg); ; r5 = A lis r4, ha16(A) lwz r5, lo16(A)(r4) ; r6 = B lis r4, ha16(B) lwz r6, lo16(B)(r4) cmpw cr0,r5,r6 ; if (r5::A <= r6::B) goto ifend ble ifend ; otherwise lis r3,hi16(ifmsg) ; r3 = ifmsg ori r3,r3,lo16(ifmsg) ; bl _print_string ; print_string(r3::ifmsg) ifend: ; fi lis r3,hi16(endmsg) ; r3 = endmsg ori r3,r3,lo16(endmsg) ; bl _print_string ; print_string(r3:endmsg) addi r1, r1, 32 ; Epilog lwz r0, 8(r1) ; mtlr r0 ; blr