!-------------------------------------- ! toascii.S ! Load and Store Instructions !-------------------------------------- .section ".rodata" pcPrompt: .asciz "Enter a character: " pcScanfFormat: .asciz "%c" pcResult: .asciz "The character's ASCII code is %d.\n" !-------------------------------------- .section ".data" !-------------------------------------- .section ".bss" pcChar: .skip 1 .align 4 piAsciiCode: .skip 4 !-------------------------------------- .section ".text" .align 4 .global main main: save %sp, -96, %sp ! printf("Enter a character: ") ; set pcPrompt, %o0 call printf nop ! scanf("%c", &cChar); set pcScanfFormat, %o0 set pcChar, %o1 call scanf nop ! iAsciiCode = (int)iChar; set pcChar, %l0 ldub [%l0], %l1 set piAsciiCode, %l2 st %l1, [%l2] ! printf("The character's ASCII code is %d.\n", iAsciiCode); set pcResult, %o0 set piAsciiCode, %o1 ld [%o1], %o1 call printf nop ! return 0; mov 0, %i0 ret restore