Input R1 has the column number of the square center 06 R0 h

Input: R1 has the column number of the square center (0-6) ; R0 has the row number of the square center (0-6)
Output: fills in the box with the current player\'s number

Notes: Calls GET_ADDRESS and puts player number in address

How to write the subroutin in Assembly Language LC3?

Solution

box:
.zero 144
fillBox(int, int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
mov DWORD PTR [rbp-12], edx
mov eax, DWORD PTR [rbp-8]
movsx rcx, eax
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, rdx
add rax, rax
add rax, rdx
add rax, rax
lea rdx, [rax+rcx]
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR box[0+rdx*4], eax
nop
pop rbp
ret

-------------------------------------------------------------------------------------------------------------------------------------------------------

Respective C code

int box[6][6];
void fillBox(int row, int col, int currentPlayer){
   box[row][col] = currentPlayer;
}

Input: R1 has the column number of the square center (0-6) ; R0 has the row number of the square center (0-6) Output: fills in the box with the current player\'

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site