Consider function print()documented below in pseudocode in the function\'s heade
ID: 3678675 • Letter: C
Question
Consider function print()documented below in pseudocode in the function's header comment block The input parameter, msg, contains the address in memory of the string to be displayed; this string is defined in the.data section. After displaying the string, by calling SysPrintStr(), it displays the integer parameter n by calling SysPrintlnt (). Note that print() is a leaf procedure since it does not call other functions. This means we do not need to save $ra in print()'s stack frame. Furthermore, since this function is small and simple enough, we can get by without allocating a stack frame at all; this is the way we shall write print(). For this exercise, write the MIPS32 assembly language code that implements print(). My optimized implementation required 6 instructions: two addi, one jr, one move, and two syscall. Note, you are not being asked to write a complete program; just implement print(). However, for testing purposes, you should write a driver main() function that calls print() to verify it works correctly.Explanation / Answer
.Ltext0: .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .globl main main: .LFB971: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 4883EC30 subq $48, %rsp 0008 64488B04 movq %fs:40, %rax 25280000 00 0011 488945F8 movq %rax, -8(%rbp) 0015 31C0 xorl %eax, %eax .LBB2: 0017 48B84865 movabsq $8031924123371070792, %rax 6C6C6F20 776F 0021 488945E0 movq %rax, -32(%rbp) 0025 C745E872 movl $560229490, -24(%rbp) 6C6421 002c C645EC00 movb $0, -20(%rbp) 0030 C745DC0A movl $10, -36(%rbp) 000000 0037 8B55DC movl -36(%rbp), %edx 003a 488D45E0 leaq -32(%rbp), %rax 003e 89D6 movl %edx, %esi 0040 4889C7 movq %rax, %rdi 0043 E8000000 call _Z7displayPci 00 0048 B8000000 movl $0, %eax 00 .LBE2: 004d 488B4DF8 movq -8(%rbp), %rcx 0051 6448330C xorq %fs:40, %rcx 25280000 00 005a 7405 je .L3 005c E8000000 call __stack_chk_fail 00 .L3: 0061 C9 leave .cfi_def_cfa 7, 8 0062 C3 ret .cfi_endproc .LFE971: .globl _Z7displayPci _Z7displayPci: .LFB972: .cfi_startproc 0063 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0064 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0067 4883EC10 subq $16, %rsp 006b 48897DF8 movq %rdi, -8(%rbp) 006f 8975F4 movl %esi, -12(%rbp) 0072 488B45F8 movq -8(%rbp), %rax 0076 4889C7 movq %rax, %rdi 0079 E8000000 call _Z11sysPrintStrPc 00 007e 8B45F4 movl -12(%rbp), %eax 0081 89C7 movl %eax, %edi 0083 E8000000 call _Z11sysPrintInti 00 0088 C9 leave .cfi_def_cfa 7, 8 0089 C3 ret .cfi_endproc .LFE972: .section .rodata .LC0: 0000 54686520 .string "The message is" 6D657373 61676520 697300 .text .globl _Z11sysPrintStrPc _Z11sysPrintStrPc: .LFB973: .cfi_startproc 008a 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 008b 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 008e 4883EC10 subq $16, %rsp 0092 48897DF8 movq %rdi, -8(%rbp) 0096 BE000000 movl $.LC0, %esi 00 009b BF000000 movl $_ZSt4cout, %edi 00 00a0 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00a5 488B55F8 movq -8(%rbp), %rdx 00a9 4889D6 movq %rdx, %rsi 00ac 4889C7 movq %rax, %rdi 00af E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00b4 C9 leave .cfi_def_cfa 7, 8 00b5 C3 ret .cfi_endproc .LFE973: .section .rodata .LC1: 000f 74686520 .string "the number is" 6E756D62 65722069 7300 .text .globl _Z11sysPrintInti _Z11sysPrintInti: .LFB974: .cfi_startproc 00b6 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00b7 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00ba 4883EC10 subq $16, %rsp 00be 897DFC movl %edi, -4(%rbp) 00c1 BE000000 movl $.LC1, %esi 00 00c6 BF000000 movl $_ZSt4cout, %edi 00 00cb E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00d0 8B55FC movl -4(%rbp), %edx 00d3 89D6 movl %edx, %esi 00d5 4889C7 movq %rax, %rdi 00d8 E8000000 call _ZNSolsEi 00 00dd C9 leave .cfi_def_cfa 7, 8 00de C3 ret .cfi_endproc .LFE974: _Z41__static_initialization_and_destruction_0ii: .LFB978: 00fc BF000000 movl $_ZStL8__ioinit, %edi 00 0101 E8000000 call _ZNSt8ios_base4InitC1Ev 00 0106 BA000000 movl $__dso_handle, %edx 00 010b BE000000 movl $_ZStL8__ioinit, %esi 00 0110 BF000000 movl $_ZNSt8ios_base4InitD1Ev, %edi 00 0115 E8000000 call __cxa_atexit 00 .cfi_startproc 00df 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00e0 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00e3 4883EC10 subq $16, %rsp 00e7 897DFC movl %edi, -4(%rbp) 00ea 8975F8 movl %esi, -8(%rbp) 00ed 837DFC01 cmpl $1, -4(%rbp) 00f1 7527 jne .L7 00f3 817DF8FF cmpl $65535, -8(%rbp) FF0000 00fa 751E jne .L7 .L7: 011a C9 leave .cfi_def_cfa 7, 8 011b C3 ret .cfi_endproc .LFE978: _GLOBAL__sub_I_main: .LFB979: .cfi_startproc 011c 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 011d 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0120 BEFFFF00 movl $65535, %esi 00 0125 BF010000 movl $1, %edi 00 012a E8B0FFFF call _Z41__static_initialization_and_destruction_0ii FF 012f 5D popq %rbp .cfi_def_cfa 7, 8 0130 C3 ret .cfi_endproc .LFE979: .section .init_array,"aw" .align 8 0000 00000000 .quad _GLOBAL__sub_I_main 00000000 .text .Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.