lab4_ex6.asm (1519B)
1 .eqv SYS_PRINT_STRING 4 2 .eqv SYS_READ_WORD 5 3 .eqv SYS_EXIT 10 4 .eqv SYS_PRINT_CHAR 11 5 6 .macro input(%msg) 7 li $v0, SYS_PRINT_STRING 8 la $a0, %msg 9 syscall 10 11 li $v0, SYS_READ_WORD 12 syscall 13 .end_macro 14 15 .macro ispositive(%val) 16 # exit if t0 or $t1 <= 0 17 beq %val, $zero, err 18 slt $t2, %val, $zero 19 bne $t2, $zero, err 20 .end_macro 21 22 .data 23 msg1: .asciiz "Lines: " 24 msg2: .asciiz "Chars: " 25 errstr: .asciiz "Give positive numbers only.\n" 26 27 .text 28 .globl main 29 30 main: 31 input(msg1) 32 move $t0, $v0 33 34 input(msg2) 35 move $t1, $v0 36 37 ispositive($t0) 38 ispositive($t1) 39 40 # init outer loop counter 41 li $t3, 0 42 43 outloop: 44 # exit if t3 == x 45 beq $t3, $t0, exit 46 addi $t3, $t3, 1 47 48 # init inner loop counter 49 li $t4, 0 50 51 # print newline 52 li $v0, SYS_PRINT_CHAR 53 li $a0, 0xa 54 syscall 55 j inloop 56 57 j outloop 58 59 inloop: 60 # break inner loop if t4 == y 61 beq $t4, $t1, outloop 62 addi $t4, $t4, 1 63 64 li $v0, SYS_PRINT_CHAR 65 li $a0, '*' 66 syscall 67 68 j inloop 69 70 err: 71 li $v0, SYS_PRINT_STRING 72 la $a0, errstr 73 syscall 74 75 exit: 76 li $v0, SYS_EXIT 77 syscall