GAS LISTING main.s page 1 1 # This is needed to link with glibc. 2 .option pic0 3 4 .rdata # read-only data 5 6 .align 2 7 promptForA: 8 0000 696E7075 .asciz "input a: " 8 7420613A 8 2000 9 10 000a 0000 .align 2 11 intFormat: 12 000c 256400 .asciz "%d" 13 14 000f 00 .align 2 15 promptForB: 16 0010 696E7075 .asciz "input b: " 16 7420623A 16 2000 17 18 001a 0000 .align 2 19 resultFormat: 20 001c 20202020 .asciz " gcd: %d\n" 20 6763643A 20 2025640A 20 00 21 22 0029 00000000 .data # read/write data follows 22 000000 23 24 .align 2 25 scanfResult: # buffer for scanf() return 26 0000 00000001 .word 1 27 28 0004 00000000 .text 28 00000000 28 00000000 29 .align 2 30 .globl main 31 .ent main 32 33 main: 34 # print the `a` prompt 35 0000 3C040000 la $a0, promptForA 36 0004 0C000000 jal printf 36 24840000 37 38 # call scanf() to put `a` in $s0 39 000c 3C040000 la $a0, intFormat 39 2484000C 40 0014 3C050000 la $a1, scanfResult 41 0018 0C000000 jal scanf 41 24A50000 42 0020 3C100000 lw $s0, scanfResult # note the explicit address 42 8E100000 43 GAS LISTING main.s page 2 44 # print the `b` prompt 45 0028 3C040000 la $a0, promptForB 46 002c 0C000000 jal printf 46 24840010 47 48 # call scanf() to put `b` in $s1 49 0034 3C040000 la $a0, intFormat 49 2484000C 50 003c 3C050000 la $a1, scanfResult 51 0040 0C000000 jal scanf 51 24A50000 52 0048 3C110000 lw $s1, scanfResult 52 8E310000 53 54 0050 02002025 move $a0, $s0 55 move $a1, $s1 56 0054 0C000000 jal gcd 56 02202825 57 005c 00408825 move $s1, $v0 58 59 # print the result with printf() 60 0060 3C040000 la $a0, resultFormat 60 2484001C 61 move $a1, $s1 62 0068 0C000000 jal printf 62 02202825 63 64 li $a0,0 65 0070 0C000000 jal exit 65 24040000 66 67 0078 00000000 .end main 67 00000000 GAS LISTING main.s page 3 DEFINED SYMBOLS main.s:7 .rodata:0000000000000000 promptForA main.s:11 .rodata:000000000000000c intFormat main.s:15 .rodata:0000000000000010 promptForB main.s:19 .rodata:000000000000001c resultFormat main.s:26 .data:0000000000000000 scanfResult main.s:33 .text:0000000000000000 main UNDEFINED SYMBOLS printf scanf gcd exit