For this exercise, write the MIPS32 assembly language code that implements getin
ID: 3677630 • Letter: F
Question
For this exercise, write the MIPS32 assembly language code that implements getint(). This implementation requires 11 instructions: four addi, one jr, two lw, two syscall, and two sw. Note, you are not being asked to write a complete program; just implement getint().
# FUNCTION: int getint (string prompt) # DESCRIPTION # Displays the prompt string (the variable 'prompt' contains the address of the string which is defined in the # . data section) using SysPrintStr(). Then calls SysReadInt() to read the integer the user enters. Returns the # integer in Svo. # PARAMETERS # $a0 prompt (addr of string to be displayed) # PSEUDOCODE # See above # RETURNS # An int in $v0 which is the integer the user typed # STACK FRAME # param prompt 4($sp) # local var n 0($sp)Explanation / Answer
OR
the program in c is:
#include "stdafx.h"
int getInt(char[]);
int getInt(char prompt[])
{
int num;
printf("%c",&prompt);
scanf("%d",&num);
return num;
}
and its associated MIPS assmbly code will be:
_TEXT SEGMENT
_num$ = -8 ; size = 4
_prompt$ = 8 ; size = 4
?getInt@@YAHQAD@Z PROC ; getInt, COMDAT
; Line 9
push ebp
mov ebp, esp
sub esp, 204 ; 000000ccH
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-204]
mov ecx, 51 ; 00000033H
mov eax, -858993460 ; ccccccccH
rep stosd
; Line 11
mov esi, esp
lea eax, DWORD PTR _prompt$[ebp]
push eax
push OFFSET ??_C@_02HAOIJKIC@?$CFc?$AA@
call DWORD PTR __imp__printf
add esp, 8
cmp esi, esp
call __RTC_CheckEsp
; Line 12
mov esi, esp
lea eax, DWORD PTR _num$[ebp]
push eax
push OFFSET ??_C@_02DPKJAMEF@?$CFd?$AA@
call DWORD PTR __imp__scanf
add esp, 8
cmp esi, esp
call __RTC_CheckEsp
; Line 13
mov eax, DWORD PTR _num$[ebp]
; Line 14
push edx
mov ecx, ebp
push eax
lea edx, DWORD PTR $LN5@getInt
call @_RTC_CheckStackVars@8
pop eax
pop edx
pop edi
pop esi
pop ebx
add esp, 204 ; 000000ccH
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
$LN5@getInt:
DD 1
DD $LN4@getInt
$LN4@getInt:
DD -8 ; fffffff8H
DD 4
DD $LN3@getInt
$LN3@getInt:
DB 110 ; 0000006eH
DB 117 ; 00000075H
DB 109 ; 0000006dH
DB 0
?getInt@@YAHQAD@Z ENDP ; getInt
_TEXT ENDS
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.