Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INCLUDE Irvine32.inc INCLUDE Macros.inc .data MAX_ROWS = 5 ; constant for num rows MAX_COLS = 5 ; constant for num cols my2DArray dword MAX_ROWS *

image text in transcribed

INCLUDE Irvine32.inc INCLUDE Macros.inc

.data MAX_ROWS = 5 ; constant for num rows MAX_COLS = 5 ; constant for num cols

my2DArray dword MAX_ROWS * MAX_COLS dup(0) ; creates 2-d array spaceStr byte " ",0 ; for displaying a space inputRow byte "Enter Row(Type 99 To Exit): ",0 ; for displaying massage for entering a Row inputColumn byte "Enter Column:",0 ; for displaying massage for entering a Col currentValue byte "The daisies there was:",0 ; for displaying massage for a Current value inputValue byte "Daisies Gathered:",0 ; for displaying massage for entering a New Valuse Bye byte "Have a Wonderful Day!!!",0 ; Displaying Have a wonderful day massage displayHeader byte "Filed of Daisies:",0 ; string to display before report

mainPoint dword ? randRow dword ? ; holds random row randCol dword ? ; holds random row randValue dword ? ; holds random value to assign into array replaceRow dword ? ; holds the replaced Row replaceColumn dword ? ; holds the replaced Column newValue dword ? ; holds the new value

multiply dword 8 ; divide dword 10 addnum sdword 0 ; add # for Row addnumc sdword 0 ; add # for Column

.code main PROC CALL Clrscr CALL randomize ; stir the pot

MOV ECX, MAX_ROWS * MAX_COLS ; Move 2-D array to ECX MOV EDI, offSet my2DArray ; display prompt 2-D array

genLoop: MOV EAX, 100 ; load EAX with upper bound for random value CALL randomRange ; generate random value 0..upper bound-1 MOV randValue, EAX MOV [EDI], EAX add EDI, type my2DArray ; edi is to stick value into array

loop genLoop

SecondLoop: Call crlf Call crlf mWrite "Filed of Daisies:" Call crlf Call crlf ; at this point my2DArray is full of 0s ; call proc to display array CALL displayMy2DArray MOV EDX, offset inputRow ; display prompt inputRow CALL writestring ; display input Row message CALL readDec ; display random row MOV replaceRow, EAX ; store random # into randRow CMP replaceRow, 99 ; quit the program when typing # 99 JE TakeCare ; get number MOV randRow, EAX ; store in memory

MOV EDX, offset inputColumn ; display prompt inputColumn CALL writestring ; display input Column CALL readDec ; get number MOV replaceColumn, EAX ; store in memory

CALL CRLF ;

MOV EDX, offset currentValue ; display prompt currentValue CALL writestring ; display Currently the value message MOV EAX, replaceRow ; get number MOV EBX, replaceColumn ; store in memory

CALL getElementOfArray ; get element at [replaceRow][replaceColumn] to newValue CALL WriteDec ; display get element of array CALL CRLF ; ;;;;;;;;;;; ;============================= ; Multiplication ;============================= ; mov edx, 0 ; 0 out edx in preparation for iMul ; MOV EAX, replaceRow ; get number ; MOV EBX, replaceColumn ; store in memory ; ; fld multiply ; fmul ; fst newValue ; ; eax*ebx ==> edx:eax contains product ; mov newValue, eax ; hold on to product ; ; ;============================= ; ; divition ; ;============================= ; MOV EAX, replaceRow ; get number ; MOV EBX, replaceColumn ; store in memory ; ; cdq ; prepares edx: eax iDiv ; ; ;iDiv eax ; eax/ebx ==> edx:eax contains quotient, edx ; mov divide, eax ; hold on to quotient ; MOV newValue, EAX ; store in memory ; mov mainPoint, edx ; hold on to remainder

;;;;;;;;;; MOV EDX, offset inputValue ; display prompt inputValue CALL writestring ; display input Value message CALL readDec ; get number MOV newValue, EAX ; store in memory MOV EAX, replaceRow ; load eax with new added row MOV EBX, replaceColumn ; load ebx with new added column MOV ECX, newValue ; load ecx with new added value ;CALL WriteDec CALL setElementOfArray ; set element at [replaceRow][replaceColumn] to newValue

JMP SecondLoop ; Jump the second loop to TakeCare

TakeCare:

CALL CRLF ; MOV EDX, offset Bye ; display prompt Good Bye message CALL writestring ; display Good Bye message CALL CRLF ;

exit main ENDP ; ============================================= ; setElementOfArray procedure expects 3 parameters ; EAX row ; EBX col ; ECX value ; ; logiCALLy this will be like: my2DArray[EAX,EBX]=ECX setElementOfArray PROC uses EDX EDI

MOV EDX, 0 ; prepare for mul

push EBX ; put EBX the column on the stack

MOV EBX, MAX_COLS*4 ; calculate the number of bytes in a row ; since EAX has the rowNum mul EBX ; EAX is now rowNum * MAX_COLS*4 - total bytes before current row MOV EDI, EAX ; put byte offset into EDI

pop EAX ; we had put EBX on the stack which was the colNum ; put that on EAX

MOV EBX, 4 ; load EBX with 4 for size of element mul EBX ; EAX is now colNum*4 which is the byte offset in the current row add EDI, EBX ; EDI is now rowNum * MAX_COLS*4 + colNum*4 ; which is the byte offset from the beginning ; of the array to this element rowNum,colNum

MOV my2DArray[EDI], ECX ; stick value in ECX into array mov ecx, 0 MOV multiply, eax mul edi ; phew! ret setElementOfArray ENDP

; ============================================= ; displayMy2DArray procedure expects no parameters ; displayMy2DArray PROC uses EDX EDI ECX EAX

mov ecx, MAX_COLS ; move ecx to coulmn push eax mov eax, 0 mWrite " " ; Sapce call padOnLeft dispCol: ; display Column Numbers call writeDec mWrite " " ; Sapce call padOnLeft ; pad with spaces inc eax loop dispCol

call crlf ; pop eax

mov ecx, MAX_COLS mov eax, 0 mWrite " " ; Sapce call padOnLeft ; pad with spaces UnderLine: mWrite " ---- " ; line of the col loop UnderLine call crlf ;

mov edi, 0 ; load edi with 0 offset

mov ecx, MAX_ROWS ; load ecx with number of rows so we can loop through rows

displayRow: ; top of outerloop on rows Mov eax, addnum call padOnLeft call writedec inc addnum mWrite" :" push ecx ; preserve ecx from outloop to use innerloop

mov ecx, MAX_COLS ; load ecx with number of cols so we can loop through cols ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; displayCol: ; top of innerloop on cols mov eax, my2DArray[edi] ; move element from array to eax for display mWrite " " call padOnLeft ; pad with spaces ; for debugging purposes show . instead of 0 ; display .

.if EAX == 0 ; if element to display is 0 push EAX ; preserve EAX MOV al, '.' ; display . CALL writeChar pop EAX ; restore EAX .else CALL writedec ; display element .endIf

;call desplayCarret

MOV EDX, offset spaceStr ; display a space CALL writestring ; display element

add EDI,4 ; advance dsi to next element

loop displayCol ; bottom of innerloop (loop on cols)

CALL CRLF ; now that a row has been displayed, MOVe to beginning of next line for next row

pop ECX ; restore ECX for outerloop on rows

loop displayRow ; bottom of outerloop (loop on rows)

mov addnum, 0 ; Start with 0 # Row mov addnumc, 0 ; Start with 0 # Column

ret ; done with this method displayMy2DArray ENDP

; ============================================= ; padOnLeft procedure expects 1 parameters ; EAX with value to pad ; padOnLeft PROC uses EDX

.if EAX

.if EAX

.if EAX

push EBX ; put EBX the column on the stack

MOV EBX, MAX_COLS*4 ; calculate the number of bytes in a row ; since EAX has the rowNum mul EBX ; EAX is now rowNum * MAX_COLS*4 - total bytes before current row MOV EDI, EAX ; put byte offset into EDI

pop EAX ; we had put EBX on the stack which was the colNum ; put that on EAX

MOV EBX, 4 ; load EBX with 4 for size of element mul EBX ; EAX is now colNum*4 which is the byte offset in the current row add EDI, EAX ; EDI is now rowNum * MAX_COLS*4 + colNum*4 ; which is the byte offset from the beginning ; of the array to this element rowNum,colNum MOV EAX, my2DArray[EDI] ; stick value in EAX into array ret ; Return getElementOfArray ENDP

Assembly language, also we are using Irvine library The "Program" begins with a "field" of daisies implemented with a 2-D array - initially there are a random number of daisies from 1..100 in each spot. The user player in possession of 0 total daisies. The player is placed in row 0 col 0. The user player's location is indicated with

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

html code Welcome to my store

Answered: 1 week ago

Question

1-4 How will MIS help my career?

Answered: 1 week ago