For Assembly Language x86: I have the following code: which currently outputs :
ID: 3741940 • Letter: F
Question
For Assembly Language x86:
I have the following code:
which currently outputs :
I would like to modify this so instead of printing out the first number of the array at the bottom, It will allow someone to pick which number they would like to output.
The output would look like:
Enter a number: 9
enter a number: 8
enter a number: 7
enter a number: 6
Pick which array number between 0-3 would you like to output:
2
8 ;// since they picked 2, it outputs the 2nd number that they entered.
.data ;// write your data in this section 13 14 15 16 17 18 19 20 21 myArray WORD 4 DUP(?) prompt BYTE "Enter a number" ,0ah, ødh, 0 prompt2 BYTE" pick a number within the array between 0-3 to output that number", 0ah, Odh, 0 .code // write your program here main proc mov eax, 0 mov edx, OFFSET prompt call Writestring call ReadInt mov myArray[o SIZEOF WORD], ax 23 24 25 26 27 28 29 30 31 32 call Writestring call ReadInt mov myArray[1*SIZEOF WORD], ax call Writestring call ReadInt mov myArray[2 * SIZEOF WORD1, ax 34 35 36 37 38 39 40 41 42 43 call Writestring call ReadInt mov myArray[3 * SIZEOF WORD], ax mov ax, myArray[0*SIZEOF WORD] call WriteDec call Crlf invoke ExitProcess,0 45 main endpExplanation / Answer
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
WriteString proto
ReadInt proto
WriteDec proto
Crlf proto
.data ;
myArray WORD 4 DUP(?)
prompt BYTE "Enter a number" ,0ah, 0dh, 0
prompt2 BYTE " pick a number within the array between 0-3 to output that number" , 0ah, 0dh , 0
.code ; // write your program here
main proc
mov eax, 0
mov edx, OFFSET prompt
call Writestring
call ReadInt
mov myArray[0*SIZEOF WORD], ax
call WriteString
call ReadInt
mov myArray[1*SIZEOF WORD], ax
call WriteString
call ReadInt
mov myArray[2 * SIZEOF WORD], ax
call WriteString
call ReadInt
mov myArray[3 * SIZEOF WORD], ax
mov edx, OFFSET prompt2
call WriteString
call ReadInt ; value is stored in eax
mov ebx, SIZE WORD
mul ebx ; multiplies eax with size of word
mov ax, [myArray + eax]
call WriteDec
call Crlf
invoke ExitProcess,0
main endp
end main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.