TITLE "demo of binary to decimal" ; Note: This code is seriously overcommented ; because it is intended for those only just learning ; about calling, receiving and return sequences. ; Note: This contains C code not yet translated to SMAL Hawk code USE "hawk.h" USE "stdio.h" INT MAIN S MAIN ; activation record structure holding local variables of MYDEC ; void mydec( unsigned int i ) { RETAD = 0 I = 4 ; int i, the parameter DIGIT = 8 ; int digit, least sig digit of i TOP = 12 ; int top, more sig digits of i ARSIZE = 16 MYDEC: ; -- start receiving sequence for mydec STORES R1,R2 ; -- save RETAD STORE R3,R2,I ; -- save and initialize I ; -- end receiving sequence for mydec ; -- start calling sequence for divideu LOAD R3,R2,I ; -- param I LIS R4,10 ; -- param 10 ADDI R2,R2,ARSIZE ; -- push AR for mydec LIL R1,DIVIDEU JSRS R1,R1 ; -- divideu( I, 10 ) gets quotient, remainder STORE R3,R2,TOP ; top = I / 10 STORE R4,R2,DIGIT ; digit = I % 10 ADDI R2,R2,-ARSIZE ; -- pop AR for mydec ; -- end calling sequence for divideu // C code not yet translated to SMAL HAwk assembly code if (top != 0) mydec( top ); // recursive call putchar( '0' + digit ); // regular call ; -- return sequence for mydec LOADS PC,R2 ; return ; -- end return sequence for mydec MAIN: STORES R1,R2 ; -- receiving sequence ; -- calling sequence begins here LIL R3,123456789 ; -- pass a param ADDSI R2,4 ; -- push AR for main JSR R1,MYDEC ; mydec( 123456789 ) ADDSI R2,-4 ; -- pop AR for main ; -- calling sequence ends here LOADS PC,R2 ; --return sequence END