(Please copy plain code, Do not screenshot!!! ) or I will report you The drunken cockroach jumps from tile-to-tile N tim
Posted: Thu Jun 02, 2022 8:20 am
(Please copy plain code, Do not screenshot!!! ) or I will report
you The drunken cockroach jumps from tile-to-tile N times, where N
is an arbitrary positive integer. Modify the program to end as soon
as the cockroach jumps to every tile at least once. The "N times"
condition no longer applies. The program may end when the cockroach
jumps less than N times, more than N times or exactly N times. The
number of times the cockroach no longer is relevant. the source
file:
TITLE Library Template
INCLUDE Irvine32.inc
INCLUDE Macros.inc
randomNumber proto ubound:dword, lbound:dword, pRandom:ptr
dword
ARRAYTYPE EQU <DWORD>
ROWINDEX EQU <esi>
COLINDEX EQU <eax>
ELMTSIZE = TYPE(ARRAYTYPE)
MAXROW = 21
MINROW = 2
MAXCOL = 51
MINCOL = 32
NROWS = MAXROW - MINROW + 1
NCOLS = MAXCOL - MINCOL + 1
ROWSIZE = NCOLS * ELMTSIZE
DELAYTIME = 256 ;milliseconds
.data
visits dword NROWS * NCOLS dup(0)
unvisited dword NROWS * NCOLS
x dword ?
y dword ?
.code
main PROC
mov eax, 0
mov edx, 0
call getmaxxy
call writeint
call crlf
mov eax, edx
call writeint
call crlf
call randomize
call clrscr
mov ecx, 256
;while unvisited > 0
@loop:
invoke randomNumber, MAXROW, MINROW, addr y
invoke randomNumber, MAXCOL, MINCOL, addr x
mov dl, byte ptr x
mov dh, byte ptr y
call gotoxy
mov al, 'A'
call writechar
mov eax, DELAYTIME
call delay
mov eax, y
sub eax, MINROW
mov ebx, ROWSIZE
mul ebx
mov esi, eax
mov eax, x
sub eax, MINCOL
inc visits[ROWINDEX + COLINDEX * ELMTSIZE]
;if visits[rowindex][colindex] = 0 then
; unvisited := unvisited - 1
loop @loop
;end while
call readchar
exit
main ENDP
randomNumber proc uses eax ebx, ubound:dword, lbound:dword,
pRandom:ptr dword
mov eax, ubound
mov ebx, lbound
cmp eax, ebx
jae @compute
xchg eax, ebx
@compute:
sub eax, ebx
inc eax
call randomRange
add eax, ebx
mov ebx, pRandom
mov [ebx], al
ret
randomNumber endp
END main
you The drunken cockroach jumps from tile-to-tile N times, where N
is an arbitrary positive integer. Modify the program to end as soon
as the cockroach jumps to every tile at least once. The "N times"
condition no longer applies. The program may end when the cockroach
jumps less than N times, more than N times or exactly N times. The
number of times the cockroach no longer is relevant. the source
file:
TITLE Library Template
INCLUDE Irvine32.inc
INCLUDE Macros.inc
randomNumber proto ubound:dword, lbound:dword, pRandom:ptr
dword
ARRAYTYPE EQU <DWORD>
ROWINDEX EQU <esi>
COLINDEX EQU <eax>
ELMTSIZE = TYPE(ARRAYTYPE)
MAXROW = 21
MINROW = 2
MAXCOL = 51
MINCOL = 32
NROWS = MAXROW - MINROW + 1
NCOLS = MAXCOL - MINCOL + 1
ROWSIZE = NCOLS * ELMTSIZE
DELAYTIME = 256 ;milliseconds
.data
visits dword NROWS * NCOLS dup(0)
unvisited dword NROWS * NCOLS
x dword ?
y dword ?
.code
main PROC
mov eax, 0
mov edx, 0
call getmaxxy
call writeint
call crlf
mov eax, edx
call writeint
call crlf
call randomize
call clrscr
mov ecx, 256
;while unvisited > 0
@loop:
invoke randomNumber, MAXROW, MINROW, addr y
invoke randomNumber, MAXCOL, MINCOL, addr x
mov dl, byte ptr x
mov dh, byte ptr y
call gotoxy
mov al, 'A'
call writechar
mov eax, DELAYTIME
call delay
mov eax, y
sub eax, MINROW
mov ebx, ROWSIZE
mul ebx
mov esi, eax
mov eax, x
sub eax, MINCOL
inc visits[ROWINDEX + COLINDEX * ELMTSIZE]
;if visits[rowindex][colindex] = 0 then
; unvisited := unvisited - 1
loop @loop
;end while
call readchar
exit
main ENDP
randomNumber proc uses eax ebx, ubound:dword, lbound:dword,
pRandom:ptr dword
mov eax, ubound
mov ebx, lbound
cmp eax, ebx
jae @compute
xchg eax, ebx
@compute:
sub eax, ebx
inc eax
call randomRange
add eax, ebx
mov ebx, pRandom
mov [ebx], al
ret
randomNumber endp
END main