[09] Wrote a Tic-Tac-Toe (2player) implementation
This commit is contained in:
parent
23324814bd
commit
43f982f06f
|
@ -0,0 +1,126 @@
|
||||||
|
class Board {
|
||||||
|
// Array of 0 by default
|
||||||
|
// X=1
|
||||||
|
// O=2
|
||||||
|
field Array gameState;
|
||||||
|
field int turn;
|
||||||
|
|
||||||
|
constructor Board new() {
|
||||||
|
var int i;
|
||||||
|
let i=0;
|
||||||
|
let turn = 0;
|
||||||
|
let gameState = Array.new(9);
|
||||||
|
while(i<9) {
|
||||||
|
let gameState[i] = 0;
|
||||||
|
let i=i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
method boolean isRowTaken(int row, int value) {
|
||||||
|
if (gameState[row*3] = value &
|
||||||
|
gameState[(row*3)+1] = value &
|
||||||
|
gameState[(row*3)+2] = value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
method boolean isColumnTaken(int column, int value) {
|
||||||
|
if (gameState[column] = value &
|
||||||
|
gameState[column+3] = value &
|
||||||
|
gameState[column+6] = value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
method boolean isWon(int value) {
|
||||||
|
if (isRowTaken(0,value) | isRowTaken(1, value) | isRowTaken(1, value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isColumnTaken(0, value) | isColumnTaken(1, value) | isColumnTaken(2, value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDiagonalTaken(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
method boolean isDiagonalTaken(int value) {
|
||||||
|
// ensure center is correct first
|
||||||
|
if (~(gameState[4] = value )) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// NORTH WEST TO SOUTH EAST
|
||||||
|
if (gameState[0] = value & gameState[8] = value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameState[2] = value & gameState[6] = value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns 1 if player X won
|
||||||
|
// returns 2 if player O won
|
||||||
|
// 0 otherwise
|
||||||
|
method int winner() {
|
||||||
|
|
||||||
|
if(isWon(1)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isWon(2)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
method boolean play(int row, int column) {
|
||||||
|
var int move, remainder;
|
||||||
|
let move = 0;
|
||||||
|
|
||||||
|
if (~ (gameState[(row*3) + column] = 0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let remainder = turn - (2 * (turn/2));
|
||||||
|
if (remainder = 0) {
|
||||||
|
let move = 1;
|
||||||
|
} else {
|
||||||
|
let move = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
let gameState[row*3 + column] = move;
|
||||||
|
if (move = 1) {
|
||||||
|
do Draw.DrawX(row, column);
|
||||||
|
} else {
|
||||||
|
if (move = 2) {
|
||||||
|
do Draw.DrawO(row, column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isWon(1)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isWon(2)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (turn = 8) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let turn = turn + 1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,376 @@
|
||||||
|
function Board.new 1
|
||||||
|
push constant 2
|
||||||
|
call Memory.alloc 1
|
||||||
|
pop pointer 0
|
||||||
|
push constant 0
|
||||||
|
pop local 0
|
||||||
|
push constant 0
|
||||||
|
pop this 1
|
||||||
|
push constant 9
|
||||||
|
call Array.new 1
|
||||||
|
pop this 0
|
||||||
|
label WHILE_EXP0
|
||||||
|
push local 0
|
||||||
|
push constant 9
|
||||||
|
lt
|
||||||
|
not
|
||||||
|
if-goto WHILE_END0
|
||||||
|
push local 0
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
push constant 0
|
||||||
|
pop temp 0
|
||||||
|
pop pointer 1
|
||||||
|
push temp 0
|
||||||
|
pop that 0
|
||||||
|
push local 0
|
||||||
|
push constant 1
|
||||||
|
add
|
||||||
|
pop local 0
|
||||||
|
goto WHILE_EXP0
|
||||||
|
label WHILE_END0
|
||||||
|
push pointer 0
|
||||||
|
return
|
||||||
|
function Board.isRowTaken 0
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
call Math.multiply 2
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
call Math.multiply 2
|
||||||
|
push constant 1
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
call Math.multiply 2
|
||||||
|
push constant 2
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Board.isColumnTaken 0
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push argument 1
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
push argument 1
|
||||||
|
push constant 6
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 2
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Board.isWon 0
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push pointer 0
|
||||||
|
push constant 0
|
||||||
|
push argument 1
|
||||||
|
call Board.isRowTaken 3
|
||||||
|
push pointer 0
|
||||||
|
push constant 1
|
||||||
|
push argument 1
|
||||||
|
call Board.isRowTaken 3
|
||||||
|
or
|
||||||
|
push pointer 0
|
||||||
|
push constant 1
|
||||||
|
push argument 1
|
||||||
|
call Board.isRowTaken 3
|
||||||
|
or
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push pointer 0
|
||||||
|
push constant 0
|
||||||
|
push argument 1
|
||||||
|
call Board.isColumnTaken 3
|
||||||
|
push pointer 0
|
||||||
|
push constant 1
|
||||||
|
push argument 1
|
||||||
|
call Board.isColumnTaken 3
|
||||||
|
or
|
||||||
|
push pointer 0
|
||||||
|
push constant 2
|
||||||
|
push argument 1
|
||||||
|
call Board.isColumnTaken 3
|
||||||
|
or
|
||||||
|
if-goto IF_TRUE1
|
||||||
|
goto IF_FALSE1
|
||||||
|
label IF_TRUE1
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE1
|
||||||
|
push pointer 0
|
||||||
|
push argument 1
|
||||||
|
call Board.isDiagonalTaken 2
|
||||||
|
if-goto IF_TRUE2
|
||||||
|
goto IF_FALSE2
|
||||||
|
label IF_TRUE2
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE2
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Board.isDiagonalTaken 0
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push constant 4
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push argument 1
|
||||||
|
eq
|
||||||
|
not
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push constant 0
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push argument 1
|
||||||
|
eq
|
||||||
|
push constant 8
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 1
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE1
|
||||||
|
goto IF_FALSE1
|
||||||
|
label IF_TRUE1
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE1
|
||||||
|
push constant 2
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push argument 1
|
||||||
|
eq
|
||||||
|
push constant 6
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
and
|
||||||
|
push argument 1
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE2
|
||||||
|
goto IF_FALSE2
|
||||||
|
label IF_TRUE2
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE2
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Board.winner 0
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push pointer 0
|
||||||
|
push constant 1
|
||||||
|
call Board.isWon 2
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 1
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push pointer 0
|
||||||
|
push constant 2
|
||||||
|
call Board.isWon 2
|
||||||
|
if-goto IF_TRUE1
|
||||||
|
goto IF_FALSE1
|
||||||
|
label IF_TRUE1
|
||||||
|
push constant 2
|
||||||
|
return
|
||||||
|
label IF_FALSE1
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Board.play 2
|
||||||
|
push argument 0
|
||||||
|
pop pointer 0
|
||||||
|
push constant 0
|
||||||
|
pop local 0
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
call Math.multiply 2
|
||||||
|
push argument 2
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
pop pointer 1
|
||||||
|
push that 0
|
||||||
|
push constant 0
|
||||||
|
eq
|
||||||
|
not
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
label IF_FALSE0
|
||||||
|
push this 1
|
||||||
|
push constant 2
|
||||||
|
push this 1
|
||||||
|
push constant 2
|
||||||
|
call Math.divide 2
|
||||||
|
call Math.multiply 2
|
||||||
|
sub
|
||||||
|
pop local 1
|
||||||
|
push local 1
|
||||||
|
push constant 0
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE1
|
||||||
|
goto IF_FALSE1
|
||||||
|
label IF_TRUE1
|
||||||
|
push constant 1
|
||||||
|
pop local 0
|
||||||
|
goto IF_END1
|
||||||
|
label IF_FALSE1
|
||||||
|
push constant 2
|
||||||
|
pop local 0
|
||||||
|
label IF_END1
|
||||||
|
push argument 1
|
||||||
|
push constant 3
|
||||||
|
call Math.multiply 2
|
||||||
|
push argument 2
|
||||||
|
add
|
||||||
|
push this 0
|
||||||
|
add
|
||||||
|
push local 0
|
||||||
|
pop temp 0
|
||||||
|
pop pointer 1
|
||||||
|
push temp 0
|
||||||
|
pop that 0
|
||||||
|
push local 0
|
||||||
|
push constant 1
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE2
|
||||||
|
goto IF_FALSE2
|
||||||
|
label IF_TRUE2
|
||||||
|
push argument 1
|
||||||
|
push argument 2
|
||||||
|
call Draw.DrawX 2
|
||||||
|
pop temp 0
|
||||||
|
goto IF_END2
|
||||||
|
label IF_FALSE2
|
||||||
|
push local 0
|
||||||
|
push constant 2
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE3
|
||||||
|
goto IF_FALSE3
|
||||||
|
label IF_TRUE3
|
||||||
|
push argument 1
|
||||||
|
push argument 2
|
||||||
|
call Draw.DrawO 2
|
||||||
|
pop temp 0
|
||||||
|
label IF_FALSE3
|
||||||
|
label IF_END2
|
||||||
|
push pointer 0
|
||||||
|
push constant 1
|
||||||
|
call Board.isWon 2
|
||||||
|
if-goto IF_TRUE4
|
||||||
|
goto IF_FALSE4
|
||||||
|
label IF_TRUE4
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE4
|
||||||
|
push pointer 0
|
||||||
|
push constant 2
|
||||||
|
call Board.isWon 2
|
||||||
|
if-goto IF_TRUE5
|
||||||
|
goto IF_FALSE5
|
||||||
|
label IF_TRUE5
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE5
|
||||||
|
push this 1
|
||||||
|
push constant 8
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE6
|
||||||
|
goto IF_FALSE6
|
||||||
|
label IF_TRUE6
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
return
|
||||||
|
label IF_FALSE6
|
||||||
|
push this 1
|
||||||
|
push constant 1
|
||||||
|
add
|
||||||
|
pop this 1
|
||||||
|
push constant 0
|
||||||
|
return
|
|
@ -0,0 +1,99 @@
|
||||||
|
class Draw {
|
||||||
|
// Draws the grid
|
||||||
|
function void Grid() {
|
||||||
|
var int row;
|
||||||
|
var int startBlock;
|
||||||
|
let row = 0;
|
||||||
|
while(row<3) {
|
||||||
|
let startBlock = 32 * (row) * 16;
|
||||||
|
do Draw.Border(startBlock);
|
||||||
|
do Draw.Border(startBlock + 1);
|
||||||
|
do Draw.Border(startBlock + 2);
|
||||||
|
let row=row+1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function void Border(int location) {
|
||||||
|
var int memAddress;
|
||||||
|
let memAddress = 16384+location;
|
||||||
|
do Memory.poke(memAddress+0, -1);
|
||||||
|
do Memory.poke(memAddress+32, -32767);
|
||||||
|
do Memory.poke(memAddress+64, -32767);
|
||||||
|
do Memory.poke(memAddress+96, -32767);
|
||||||
|
do Memory.poke(memAddress+128, -32767);
|
||||||
|
do Memory.poke(memAddress+160, -32767);
|
||||||
|
do Memory.poke(memAddress+192, -32767);
|
||||||
|
do Memory.poke(memAddress+224, -32767);
|
||||||
|
do Memory.poke(memAddress+256, -32767);
|
||||||
|
do Memory.poke(memAddress+288, -32767);
|
||||||
|
do Memory.poke(memAddress+320, -32767);
|
||||||
|
do Memory.poke(memAddress+352, -32767);
|
||||||
|
do Memory.poke(memAddress+384, -32767);
|
||||||
|
do Memory.poke(memAddress+416, -32767);
|
||||||
|
do Memory.poke(memAddress+448, -32767);
|
||||||
|
do Memory.poke(memAddress+480, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function int Location(int row, int column) {
|
||||||
|
return (32 * row * 16) + column;
|
||||||
|
}
|
||||||
|
|
||||||
|
function void DrawX(int row, int column) {
|
||||||
|
var int l;
|
||||||
|
let l = Draw.Location(row, column);
|
||||||
|
do Draw.X(l);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
function void DrawO(int row, int column) {
|
||||||
|
var int l;
|
||||||
|
let l = Draw.Location(row, column);
|
||||||
|
do Draw.O(l);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function void X(int location) {
|
||||||
|
var int memAddress;
|
||||||
|
let memAddress = 16384+location;
|
||||||
|
do Memory.poke(memAddress+0, -1);
|
||||||
|
do Memory.poke(memAddress+32, -32767);
|
||||||
|
do Memory.poke(memAddress+64, -20467);
|
||||||
|
do Memory.poke(memAddress+96, -18403);
|
||||||
|
do Memory.poke(memAddress+128, -25543);
|
||||||
|
do Memory.poke(memAddress+160, -29071);
|
||||||
|
do Memory.poke(memAddress+192, -31807);
|
||||||
|
do Memory.poke(memAddress+224, -31807);
|
||||||
|
do Memory.poke(memAddress+256, -31807);
|
||||||
|
do Memory.poke(memAddress+288, -31807);
|
||||||
|
do Memory.poke(memAddress+320, -29071);
|
||||||
|
do Memory.poke(memAddress+352, -25543);
|
||||||
|
do Memory.poke(memAddress+384, -18403);
|
||||||
|
do Memory.poke(memAddress+416, -20467);
|
||||||
|
do Memory.poke(memAddress+448, -32767);
|
||||||
|
do Memory.poke(memAddress+480, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function void O(int location) {
|
||||||
|
var int memAddress;
|
||||||
|
let memAddress = 16384+location;
|
||||||
|
do Memory.poke(memAddress+0, -1);
|
||||||
|
do Memory.poke(memAddress+32, -32767);
|
||||||
|
do Memory.poke(memAddress+64, -28687);
|
||||||
|
do Memory.poke(memAddress+96, -24583);
|
||||||
|
do Memory.poke(memAddress+128, -20467);
|
||||||
|
do Memory.poke(memAddress+160, -20467);
|
||||||
|
do Memory.poke(memAddress+192, -20467);
|
||||||
|
do Memory.poke(memAddress+224, -20467);
|
||||||
|
do Memory.poke(memAddress+256, -20467);
|
||||||
|
do Memory.poke(memAddress+288, -20467);
|
||||||
|
do Memory.poke(memAddress+320, -20467);
|
||||||
|
do Memory.poke(memAddress+352, -20467);
|
||||||
|
do Memory.poke(memAddress+384, -24583);
|
||||||
|
do Memory.poke(memAddress+416, -28687);
|
||||||
|
do Memory.poke(memAddress+448, -32767);
|
||||||
|
do Memory.poke(memAddress+480, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,422 @@
|
||||||
|
function Draw.Grid 2
|
||||||
|
push constant 0
|
||||||
|
pop local 0
|
||||||
|
label WHILE_EXP0
|
||||||
|
push local 0
|
||||||
|
push constant 3
|
||||||
|
lt
|
||||||
|
not
|
||||||
|
if-goto WHILE_END0
|
||||||
|
push constant 32
|
||||||
|
push local 0
|
||||||
|
call Math.multiply 2
|
||||||
|
push constant 16
|
||||||
|
call Math.multiply 2
|
||||||
|
pop local 1
|
||||||
|
push local 1
|
||||||
|
call Draw.Border 1
|
||||||
|
pop temp 0
|
||||||
|
push local 1
|
||||||
|
push constant 1
|
||||||
|
add
|
||||||
|
call Draw.Border 1
|
||||||
|
pop temp 0
|
||||||
|
push local 1
|
||||||
|
push constant 2
|
||||||
|
add
|
||||||
|
call Draw.Border 1
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 1
|
||||||
|
add
|
||||||
|
pop local 0
|
||||||
|
goto WHILE_EXP0
|
||||||
|
label WHILE_END0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Draw.Border 1
|
||||||
|
push constant 16384
|
||||||
|
push argument 0
|
||||||
|
add
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
push constant 0
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 32
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 64
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 96
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 128
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 160
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 192
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 224
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 256
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 288
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 320
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 352
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 384
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 416
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 448
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 480
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Draw.Location 0
|
||||||
|
push constant 32
|
||||||
|
push argument 0
|
||||||
|
call Math.multiply 2
|
||||||
|
push constant 16
|
||||||
|
call Math.multiply 2
|
||||||
|
push argument 1
|
||||||
|
add
|
||||||
|
return
|
||||||
|
function Draw.DrawX 1
|
||||||
|
push argument 0
|
||||||
|
push argument 1
|
||||||
|
call Draw.Location 2
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
call Draw.X 1
|
||||||
|
pop temp 0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Draw.DrawO 1
|
||||||
|
push argument 0
|
||||||
|
push argument 1
|
||||||
|
call Draw.Location 2
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
call Draw.O 1
|
||||||
|
pop temp 0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Draw.X 1
|
||||||
|
push constant 16384
|
||||||
|
push argument 0
|
||||||
|
add
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
push constant 0
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 32
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 64
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 96
|
||||||
|
add
|
||||||
|
push constant 18403
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 128
|
||||||
|
add
|
||||||
|
push constant 25543
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 160
|
||||||
|
add
|
||||||
|
push constant 29071
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 192
|
||||||
|
add
|
||||||
|
push constant 31807
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 224
|
||||||
|
add
|
||||||
|
push constant 31807
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 256
|
||||||
|
add
|
||||||
|
push constant 31807
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 288
|
||||||
|
add
|
||||||
|
push constant 31807
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 320
|
||||||
|
add
|
||||||
|
push constant 29071
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 352
|
||||||
|
add
|
||||||
|
push constant 25543
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 384
|
||||||
|
add
|
||||||
|
push constant 18403
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 416
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 448
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 480
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push constant 0
|
||||||
|
return
|
||||||
|
function Draw.O 1
|
||||||
|
push constant 16384
|
||||||
|
push argument 0
|
||||||
|
add
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
push constant 0
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 32
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 64
|
||||||
|
add
|
||||||
|
push constant 28687
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 96
|
||||||
|
add
|
||||||
|
push constant 24583
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 128
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 160
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 192
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 224
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 256
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 288
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 320
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 352
|
||||||
|
add
|
||||||
|
push constant 20467
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 384
|
||||||
|
add
|
||||||
|
push constant 24583
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 416
|
||||||
|
add
|
||||||
|
push constant 28687
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 448
|
||||||
|
add
|
||||||
|
push constant 32767
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push local 0
|
||||||
|
push constant 480
|
||||||
|
add
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
call Memory.poke 2
|
||||||
|
pop temp 0
|
||||||
|
push constant 0
|
||||||
|
return
|
|
@ -0,0 +1,55 @@
|
||||||
|
class Main {
|
||||||
|
function void main() {
|
||||||
|
var int c,position;
|
||||||
|
var Board b;
|
||||||
|
var char key; // the key currently pressed by the user
|
||||||
|
var boolean exit;
|
||||||
|
var boolean gameend;
|
||||||
|
|
||||||
|
let exit = false;
|
||||||
|
let b = Board.new();
|
||||||
|
|
||||||
|
do Draw.Grid();
|
||||||
|
|
||||||
|
while(~exit) {
|
||||||
|
while (key = 0) {
|
||||||
|
let key = Keyboard.keyPressed();
|
||||||
|
do Sys.wait(5); // wait 5ms
|
||||||
|
}
|
||||||
|
|
||||||
|
let position = -1;
|
||||||
|
|
||||||
|
if (key = 81) { let exit = true; } // q
|
||||||
|
if (key = 49) { let position = 0; } // 1
|
||||||
|
if (key = 50) { let position = 1; }
|
||||||
|
if (key = 51) { let position = 2; }
|
||||||
|
if (key = 52) { let position = 3; }
|
||||||
|
if (key = 53) { let position = 4; }
|
||||||
|
if (key = 54) { let position = 5; }
|
||||||
|
if (key = 55) { let position = 6; }
|
||||||
|
if (key = 56) { let position = 7; }
|
||||||
|
if (key = 57) { let position = 8; } // 9
|
||||||
|
|
||||||
|
if((key>48)&(key<58)) {
|
||||||
|
let c = position - (3 * (position/3));
|
||||||
|
let gameend = b.play(position/3, c);
|
||||||
|
if (gameend) {
|
||||||
|
do Screen.clearScreen();
|
||||||
|
let c = b.winner();
|
||||||
|
if(c = 1) {
|
||||||
|
do Output.printString("Congratulations Player 1");
|
||||||
|
}
|
||||||
|
if (c = 2) {
|
||||||
|
do Output.printString("Congratulations Player 2");
|
||||||
|
}
|
||||||
|
if (c = 0) {
|
||||||
|
do Output.printString("It was a draw!");
|
||||||
|
}
|
||||||
|
let exit = true;
|
||||||
|
}
|
||||||
|
let key = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,321 @@
|
||||||
|
function Main.main 6
|
||||||
|
push constant 0
|
||||||
|
pop local 4
|
||||||
|
call Board.new 0
|
||||||
|
pop local 2
|
||||||
|
call Draw.Grid 0
|
||||||
|
pop temp 0
|
||||||
|
label WHILE_EXP0
|
||||||
|
push local 4
|
||||||
|
not
|
||||||
|
not
|
||||||
|
if-goto WHILE_END0
|
||||||
|
label WHILE_EXP1
|
||||||
|
push local 3
|
||||||
|
push constant 0
|
||||||
|
eq
|
||||||
|
not
|
||||||
|
if-goto WHILE_END1
|
||||||
|
call Keyboard.keyPressed 0
|
||||||
|
pop local 3
|
||||||
|
push constant 5
|
||||||
|
call Sys.wait 1
|
||||||
|
pop temp 0
|
||||||
|
goto WHILE_EXP1
|
||||||
|
label WHILE_END1
|
||||||
|
push constant 1
|
||||||
|
neg
|
||||||
|
pop local 1
|
||||||
|
push local 3
|
||||||
|
push constant 81
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE0
|
||||||
|
goto IF_FALSE0
|
||||||
|
label IF_TRUE0
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
pop local 4
|
||||||
|
label IF_FALSE0
|
||||||
|
push local 3
|
||||||
|
push constant 49
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE1
|
||||||
|
goto IF_FALSE1
|
||||||
|
label IF_TRUE1
|
||||||
|
push constant 0
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE1
|
||||||
|
push local 3
|
||||||
|
push constant 50
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE2
|
||||||
|
goto IF_FALSE2
|
||||||
|
label IF_TRUE2
|
||||||
|
push constant 1
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE2
|
||||||
|
push local 3
|
||||||
|
push constant 51
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE3
|
||||||
|
goto IF_FALSE3
|
||||||
|
label IF_TRUE3
|
||||||
|
push constant 2
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE3
|
||||||
|
push local 3
|
||||||
|
push constant 52
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE4
|
||||||
|
goto IF_FALSE4
|
||||||
|
label IF_TRUE4
|
||||||
|
push constant 3
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE4
|
||||||
|
push local 3
|
||||||
|
push constant 53
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE5
|
||||||
|
goto IF_FALSE5
|
||||||
|
label IF_TRUE5
|
||||||
|
push constant 4
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE5
|
||||||
|
push local 3
|
||||||
|
push constant 54
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE6
|
||||||
|
goto IF_FALSE6
|
||||||
|
label IF_TRUE6
|
||||||
|
push constant 5
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE6
|
||||||
|
push local 3
|
||||||
|
push constant 55
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE7
|
||||||
|
goto IF_FALSE7
|
||||||
|
label IF_TRUE7
|
||||||
|
push constant 6
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE7
|
||||||
|
push local 3
|
||||||
|
push constant 56
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE8
|
||||||
|
goto IF_FALSE8
|
||||||
|
label IF_TRUE8
|
||||||
|
push constant 7
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE8
|
||||||
|
push local 3
|
||||||
|
push constant 57
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE9
|
||||||
|
goto IF_FALSE9
|
||||||
|
label IF_TRUE9
|
||||||
|
push constant 8
|
||||||
|
pop local 1
|
||||||
|
label IF_FALSE9
|
||||||
|
push local 3
|
||||||
|
push constant 48
|
||||||
|
gt
|
||||||
|
push local 3
|
||||||
|
push constant 58
|
||||||
|
lt
|
||||||
|
and
|
||||||
|
if-goto IF_TRUE10
|
||||||
|
goto IF_FALSE10
|
||||||
|
label IF_TRUE10
|
||||||
|
push local 1
|
||||||
|
push constant 3
|
||||||
|
push local 1
|
||||||
|
push constant 3
|
||||||
|
call Math.divide 2
|
||||||
|
call Math.multiply 2
|
||||||
|
sub
|
||||||
|
pop local 0
|
||||||
|
push local 2
|
||||||
|
push local 1
|
||||||
|
push constant 3
|
||||||
|
call Math.divide 2
|
||||||
|
push local 0
|
||||||
|
call Board.play 3
|
||||||
|
pop local 5
|
||||||
|
push local 5
|
||||||
|
if-goto IF_TRUE11
|
||||||
|
goto IF_FALSE11
|
||||||
|
label IF_TRUE11
|
||||||
|
call Screen.clearScreen 0
|
||||||
|
pop temp 0
|
||||||
|
push local 2
|
||||||
|
call Board.winner 1
|
||||||
|
pop local 0
|
||||||
|
push local 0
|
||||||
|
push constant 1
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE12
|
||||||
|
goto IF_FALSE12
|
||||||
|
label IF_TRUE12
|
||||||
|
push constant 24
|
||||||
|
call String.new 1
|
||||||
|
push constant 67
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 111
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 110
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 103
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 114
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 116
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 117
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 108
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 116
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 105
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 111
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 110
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 115
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 80
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 108
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 121
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 101
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 114
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 49
|
||||||
|
call String.appendChar 2
|
||||||
|
call Output.printString 1
|
||||||
|
pop temp 0
|
||||||
|
label IF_FALSE12
|
||||||
|
push local 0
|
||||||
|
push constant 2
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE13
|
||||||
|
goto IF_FALSE13
|
||||||
|
label IF_TRUE13
|
||||||
|
push constant 24
|
||||||
|
call String.new 1
|
||||||
|
push constant 67
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 111
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 110
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 103
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 114
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 116
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 117
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 108
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 116
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 105
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 111
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 110
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 115
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 80
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 108
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 121
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 101
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 114
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 50
|
||||||
|
call String.appendChar 2
|
||||||
|
call Output.printString 1
|
||||||
|
pop temp 0
|
||||||
|
label IF_FALSE13
|
||||||
|
push local 0
|
||||||
|
push constant 0
|
||||||
|
eq
|
||||||
|
if-goto IF_TRUE14
|
||||||
|
goto IF_FALSE14
|
||||||
|
label IF_TRUE14
|
||||||
|
push constant 14
|
||||||
|
call String.new 1
|
||||||
|
push constant 73
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 116
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 119
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 115
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 32
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 100
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 114
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 97
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 119
|
||||||
|
call String.appendChar 2
|
||||||
|
push constant 33
|
||||||
|
call String.appendChar 2
|
||||||
|
call Output.printString 1
|
||||||
|
pop temp 0
|
||||||
|
label IF_FALSE14
|
||||||
|
push constant 0
|
||||||
|
not
|
||||||
|
pop local 4
|
||||||
|
label IF_FALSE11
|
||||||
|
push constant 0
|
||||||
|
pop local 3
|
||||||
|
label IF_FALSE10
|
||||||
|
goto WHILE_EXP0
|
||||||
|
label WHILE_END0
|
||||||
|
push constant 0
|
||||||
|
return
|
Loading…
Reference in New Issue