; bitswap: PeANUt assembler (test) program for COMP2300 Lab Exercise 5 macro Put (e) ; write value of e to terminal load e ; (AC = ) trap #3 ; (AC(0:7) written to standard output) endmacro macro Call2 (Proc, e1, e2); call procedure Proc, with 2 value parameters (e1,e2) ; or a function Proc, with 1 value parameter (e2) ; and stack is used for return value (e1=#0) load e1 ; (AC = ) incsp #1 ; (SP = SP + 1) store !0 ; (Memory[SP] = AC) load e2 ; (AC = ) incsp #1 ; (SP = SP + 1) store !0 ; (Memory[SP] = AC) call Proc ; (call procedure Proc) incsp #-2 ; (restore stack) endmacro ; This program inputs a character, prints it out in character and ; binary form, and prints out the character with bits 0..3 and bits 4..7 ; swapped. ; #include external WriteBin ; #include "fpio.h" external SwapBits ; #include "swapbits.h" /*SwapBits()*/ ; int main() { ch: block 1 ; char ch: CHAR; ch1: block 1 ; unsigned short int ch1; /* copy of ch */ bitswap: ; trap #2 ; ch = getchar(); store ch ; load ch ; ch1 = ch; store ch1 ; ; SwapBits( &ch ); /* pass address of ch */ ; ; ; ; Put (ch1) ; putchar(ch1); Put (#' ') ; putchar(' '); Call2 (WriteBin, ch1, #8);WriteBin( ch1, 8 ); Put (#'\n') ; putchar('\n'); ; Put (ch) ; putchar(ch); Put (#' ') ; putchar(' '); Call2 (WriteBin, ch, #8); WriteBin( ch, 8 ); Put (#'\n') ; putchar('\n'); trap #1 ; } /*main() */ end bitswap ;