Friday March 5th Write a MAL Program that rads two chars and displays the one that comes first alphabetically __start: getc $9 getc $10 blt $9,$10, firstlower put $10 b end firstlower: putc $9 end: done #$8 store first char input #$9 store last char input #$10: holds smaller char #$11: holds newline Write a MAL program that does the equivalent of puts str .data str: .asciiz "String" .text la $9,str loop: lbu $10,($9) putc $10 add $9,$9,1 bne $10, $0, loop done # Simple int read/write program # $9: input char # $10: newline # $11: '0' (lower limit) # $12: '9' (upper limit) # $13: intvalue of the current digit # $14: intvalue of input .data str1: .asciiz "Enter a non-negative integer:" str2: .asciiz "You've entered: " str3: .asciiz "Error!" newline: .byte '\n' # vars: int_array .word 0:20 .text __start: puts str1 lbu $10,newline li $11, '0' li $12, '9' move $14, $0 get_chars: getc $9 beq $9,$10, gotint blt $9, $11, interr bgt $9, $12, interr sub $13, $9, '0' mul $14, $14, 10 add $14, $14, $12 b get_chars interr: puts str3 end: done # MAL CODE for wiring out an int. # $14: int to be printed # $15: Base Address of the array storing the digits # $16: Elem Addr of ------^ # $17: Single digit of the int # $18: Single char digit of the int get_int: puts str2 la $15, int_array move $16, $15 more_digits: rem $17, $14, 10 sw $17, ($16) add $16, $16, 4 div $14, $14, 10 bgtz $14, more_digits print_digit: sub $16,$16,4 lw $18,($16) add $18,$18,'0' putc $18 bgt $16, $15, print_digit Tools: MAL Tester Run: %MALtester If Good: *********** This is MAL *********** %simp easy for remote use console app simple simulator %sim Simulator Xterm interface - GUI Remote Execution requires an xterm emulator set breakpoints see contents of registers Prob: input isnt buffered for sim simp buffers input so a return mut be entered to finish input HLL: Procedure call x = larger (a,b) Procedure: MAL impl of SAL procedure: Basic steps: 1. Load the return addr 2. Call procedure 3. Execute prcoedure 4. Return MAL imp of SAL procedure la $11, rtn1 b proc1 proc1: jr $11 jal proc1 rtn2: #rtn address is stored in register $31