Initial work on Fill.asm
Scrapped everything I did yesterday, basing it on scratch from what I wrote in manual-fill.asm
This commit is contained in:
parent
90526cc036
commit
25e828ec9d
|
@ -6,9 +6,77 @@
|
|||
// Runs an infinite loop that listens to the keyboard input.
|
||||
// When a key is pressed (any key), the program blackens the screen,
|
||||
// i.e. writes "black" in every pixel;
|
||||
// the screen should remain fully black as long as the key is pressed.
|
||||
// the screen should remain fully black as long as the key is pressed.
|
||||
// When no key is pressed, the program clears the screen, i.e. writes
|
||||
// "white" in every pixel;
|
||||
// the screen should remain fully clear as long as no key is pressed.
|
||||
|
||||
// Put your code here.
|
||||
// Set i to 255
|
||||
@255
|
||||
D=A
|
||||
@i
|
||||
M=D
|
||||
|
||||
(KEYBOARD_LOOP)
|
||||
|
||||
// Read the Keyboard and set color
|
||||
@color
|
||||
M=0
|
||||
@KBD
|
||||
D=M
|
||||
@ENDKBDIF
|
||||
D;JEQ
|
||||
// If keyboard is pressed
|
||||
@0
|
||||
D=A
|
||||
D=D-1
|
||||
@color
|
||||
M=D
|
||||
(ENDKBDIF)
|
||||
|
||||
// At this point @color = 0|-1 depending on whether a key is pressed
|
||||
|
||||
// This is adapted from manual-fill.asm
|
||||
|
||||
|
||||
// coloring code goes here
|
||||
|
||||
|
||||
@color
|
||||
D=M
|
||||
|
||||
@SCREEN
|
||||
M=D
|
||||
|
||||
|
||||
// Keyboard Loop ending
|
||||
|
||||
// Reduce i by 1
|
||||
@i
|
||||
M=M-1
|
||||
|
||||
// Jump to ENDIF if @i>0
|
||||
@i
|
||||
D=M
|
||||
@ENDIF
|
||||
D;JGT
|
||||
|
||||
// Here i==0, so we reset it to 255
|
||||
@255
|
||||
D=A
|
||||
@i
|
||||
M=D
|
||||
|
||||
(ENDIF)
|
||||
|
||||
|
||||
@KEYBOARD_LOOP
|
||||
0;JMP
|
||||
|
||||
|
||||
// @WRITE_COMPLETE_ROW
|
||||
// 0;JMP
|
||||
|
||||
(END)
|
||||
@END
|
||||
0;JMP
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
0000000011111111
|
||||
1110110000010000
|
||||
0000000000010000
|
||||
1110001100001000
|
||||
0000000000010001
|
||||
1110101010001000
|
||||
0110000000000000
|
||||
1111110000010000
|
||||
0000000000001111
|
||||
1110001100000010
|
||||
0000000000000000
|
||||
1110110000010000
|
||||
1110001110010000
|
||||
0000000000010001
|
||||
1110001100001000
|
||||
1110101010010000
|
||||
0000000000010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
1111000010010000
|
||||
0100000000000000
|
||||
1110000010110000
|
||||
0000000000010010
|
||||
1110001100001000
|
||||
0000000000010000
|
||||
1111110000010000
|
||||
0000000000111101
|
||||
1110001100000001
|
||||
0000000011111111
|
||||
1110110000010000
|
||||
0000000000010000
|
||||
1110001100001000
|
||||
0000000000010001
|
||||
1111110000010000
|
||||
0000000000010010
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010010
|
||||
1111110111100000
|
||||
1111110000100000
|
||||
1110001100001000
|
||||
0000000000010000
|
||||
1111110010001000
|
||||
0000000000000100
|
||||
1110101010000111
|
|
@ -0,0 +1,3 @@
|
|||
|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
|
||||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| -1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
|
@ -0,0 +1,137 @@
|
|||
// This program does a manual fill for the entire screen
|
||||
// Loops over all rows (255) and calls
|
||||
// a screen write operation 32 times for each row
|
||||
// each row has 512 pixels = 16 * 32 bits = 32 registers
|
||||
// so each row takes 32 memory addresses in the RAM, starting from @SCREEN
|
||||
|
||||
// The program uses the following:
|
||||
// @i : A counter that goes from 255->0
|
||||
// : program ends when it reaches 0
|
||||
// : this keeps track of how many rows have we covered
|
||||
|
||||
// @R0: This stores the address of the first memory address for the
|
||||
// : row of the screen that we are filling right now
|
||||
// : Initialized by setting it to @SCREEN
|
||||
|
||||
// @color: Stores -1, since we can't use that as a constant.
|
||||
// : Copied to D register before being written to screen
|
||||
@0
|
||||
D=A
|
||||
D=D-1
|
||||
@color
|
||||
M=D
|
||||
// Now color holds -1
|
||||
|
||||
// Set counter to 255
|
||||
@255
|
||||
D=A
|
||||
@i
|
||||
M=D
|
||||
|
||||
// Store our initial screen row address in D
|
||||
@SCREEN
|
||||
D=A
|
||||
// And then save it in R0
|
||||
@R0
|
||||
M=D
|
||||
|
||||
// This is our screen/row writing loop
|
||||
(WRITE_COMPLETE_ROW)
|
||||
// Read color in D
|
||||
@color
|
||||
D=M
|
||||
// Load the value in R0 to A
|
||||
@R0
|
||||
A=M
|
||||
// And off we go hunting
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
A=A+1
|
||||
M=D
|
||||
|
||||
// Bump A by 1 and write it to R0
|
||||
A=A+1
|
||||
D=A
|
||||
@R0
|
||||
M=D
|
||||
|
||||
// Reduce i by 1
|
||||
@i
|
||||
M=M-1
|
||||
|
||||
// Jump to ENDIF if @i>0
|
||||
@i
|
||||
D=M
|
||||
@ENDIF
|
||||
D;JGT
|
||||
|
||||
// If i==0, jump to end
|
||||
@END
|
||||
0;JMP
|
||||
(ENDIF)
|
||||
|
||||
@WRITE_COMPLETE_ROW
|
||||
0;JMP
|
||||
|
||||
(END)
|
||||
@END
|
||||
0;JMP
|
|
@ -0,0 +1,94 @@
|
|||
@i
|
||||
M=255
|
||||
|
||||
@j
|
||||
M=32
|
||||
|
||||
@i
|
||||
D=M
|
||||
@OUTERLOOPENDS
|
||||
D;JEQ
|
||||
|
||||
// Set j=0
|
||||
@j
|
||||
M=0
|
||||
|
||||
@j
|
||||
D=M
|
||||
@INNERLOOPENDS
|
||||
D;JEQ
|
||||
|
||||
// INNER LOOP
|
||||
|
||||
// Set R0=i
|
||||
@i
|
||||
D=M
|
||||
@R0
|
||||
M=D
|
||||
|
||||
// Set R1=32
|
||||
@32
|
||||
D=A
|
||||
@R1
|
||||
M=D
|
||||
|
||||
@after_multiply
|
||||
0;JMP
|
||||
|
||||
(after_multiply)
|
||||
|
||||
|
||||
// INNER LOOP
|
||||
|
||||
|
||||
(INNERLOOPENDS)
|
||||
|
||||
@i
|
||||
M=M-1
|
||||
|
||||
(OUTERLOOPENDS)
|
||||
|
||||
// SET A to return address
|
||||
// Multiplies R0 with R1 and sets it to R2
|
||||
(MULTIPLY_WITH_32)
|
||||
// Save return address to R3
|
||||
D=A
|
||||
@R3
|
||||
M=D
|
||||
|
||||
@R2
|
||||
M=0
|
||||
|
||||
// Put your code here.
|
||||
(MLOOP)
|
||||
|
||||
@R0
|
||||
D=M
|
||||
// Jump to end if R0 = 0
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
@R2
|
||||
D=M
|
||||
|
||||
@R1
|
||||
// Increase D by R1
|
||||
D=D+M
|
||||
|
||||
// Save final value back to result
|
||||
|
||||
@R2
|
||||
M=D
|
||||
|
||||
// R0=R0-1
|
||||
@R0
|
||||
M=M-1
|
||||
|
||||
// Otherwise, go to loop
|
||||
@LOOP
|
||||
0;JMP
|
||||
|
||||
// AFTER we're done
|
||||
// We do an unconditional jump to A
|
||||
@R3
|
||||
0;JMP
|
|
@ -0,0 +1,11 @@
|
|||
@20
|
||||
D=A
|
||||
@addr
|
||||
M=D
|
||||
|
||||
@addr
|
||||
A=M
|
||||
M=1
|
||||
// @addr
|
||||
// A=A+1
|
||||
// M=1
|
Loading…
Reference in New Issue