! as -o smul.o smul.s ; ld -o smul smul.o .equ SYSCALL_EXIT,1 .equ SYSCALL_WRITE,4 .equ STDOUT,1 .globl _start _start: set 0xc22e4507,%g1 set 0x386d4380,%g4 before: smul %g4,%g1,%g2 rd %y,%g3 stop: ! g2 should be (f25fbc80) 1f2e5880 ! g3 should be (00000000) f25fbc80 set 0x1f2e5880,%g5 cmp %g2,%g5 bne wrong_lower nop set correct_answer,%o1 ba print_lower nop wrong_lower: set wrong_answer,%o1 print_lower: call write_stdout nop ! Check to see if Y was correct set 0xf25fbc80,%g5 cmp %g3,%g5 bne print_wrong_y nop set correct_y,%o1 ba print_y nop print_wrong_y: set wrong_y,%o1 print_y: call write_stdout nop !================================ ! Exit !================================ exit: mov 0,%o0 ! exit value mov SYSCALL_EXIT,%g1 ! put the exit syscall number in g1 ta 0x10 ! and exit #================================ # WRITE_STDOUT #================================ # %o1 has string write_stdout: set SYSCALL_WRITE,%g1 ! Write syscall in %g1 set STDOUT,%o0 ! 1 in %o0 (stdout) set 0,%o2 ! 0 (count) in %o2 str_loop1: ldub [%o1+%o2],%l1 ! load byte cmp %l1,%g0 ! compare against zero bnz str_loop1 ! if not nul, repeat # BRANCH DELAY SLOT inc %o2 ! increment count dec %o2 ! correct count ta 0x10 ! run the syscall retl nop !=========================================================================== .data !=========================================================================== data_region: wrong_answer: .ascii "Wrong answer\n\0" wrong_y: .ascii "Wrong Y\n\0" correct_answer: .ascii "Correct answer\n\0" correct_y: .ascii "Correct Y\n\0"