# Box-256 Assembly - BIG SQUARE II

I'd like to start a series of challenges for http://box-256.com/ starting with the first challenge, “BIG SQUARE II”. After this one I'll add another for "CHECKERBOARD" and so on.

Rules:

• Complete the BIG SQAURE II challenge in the Box-256 emulator (either on the website or download the program if you run Windows)
• You MUST include the code in plain text so that others can easily copy and very it’s operation.

Scoring:

The winner will be the least amount of instructions used (just the instruction calls, either by name or opcode, the arguments to them are not counted as JMP takes one argument but MOD can take three).

I think in the future contests we can add some additional bonus points for use of coding tricks and we could include the argument count too. I wanted to start basic to get the ball rolling.

Winning

I think we should put a stake in the ground and say two weeks from today we announce the winner(s, there maybe be mutliple entries with the same instruction count).

• I'm confused It says BIGSQUARE in the title but you should solve BIGSQUARE2?? – CalculatorFeline Apr 15 '16 at 1:06
• @CatsAreFluffy Thanks for pointing that out, I have amended the title. It should have been BIG SQUARE II since the first BIG SQUARE challenge is already solved on the box-256 homepage with a very efficient answer. – jwbensley Apr 15 '16 at 7:33
• How about we score by memory rows? – CalculatorFeline Apr 15 '16 at 15:20
• @jwbensley please can you clairify the scoring. 1) will data lines with no instruction / opcode count towards the score? 2) will overlapping / misaligned code count as the number of instructions they actually execute or the number of lines they occupy? – impomatic Apr 19 '16 at 10:49
• @jwbensley 3) does executing empty memory / invalid instructions count towards the score? (e.g. if I leave off the final JMP at the end of the code and let the program execute the unused memory before returning to 00) – impomatic Apr 21 '16 at 14:21

# 1 instruction

This solution is to illustrate that counting instructions is not a proper way of scoring for BOX-256.

JMP 002 072 00C
002 000 013 00C
001 00C 055 002
010 000 000 000
011 012 013 014
015 016 017 018
019 01A 01B 01C
01D 01E 021 022
023 024 025 026
027 028 029 02A
02B 02C 02D 02E
0D1 0D2 0D3 0D4
0D5 0D6 0D7 0D8
0D9 0DA 0DB 0DC
0DD 0DE 0E1 0E2
0E3 0E4 0E5 0E6
0E7 0E8 0E9 0EA
0EB 0EC 0ED 0EE
031 041 051 061
071 081 091 0A1
0B1 0C1 032 042
052 062 072 082
092 0A2 0B2 0C2
03D 04D 05D 06D
0BD 0CD 0ED 03E
04E 05E 06E 07E
08E 09E 0AE 0BE
0CE 000 000 000


• Do you need JMP 002? – CalculatorFeline Apr 15 '16 at 1:13
• @CatsAreFluffy Sadly it's not possible to directly set the instruction pointer in BOX-256 as an initial parameter, so you need an initial instruction. – orlp Apr 15 '16 at 1:17
• Hmm...Well how do you get the plaintext version of the programs? – CalculatorFeline Apr 15 '16 at 1:33
• JMP with @ ≠ JMP with 0 ≠ JMP with * – CalculatorFeline Apr 15 '16 at 15:20
• @impomatic Maybe, I haven't tried :) But LOC is still wrong. We should just score by bytes. – orlp Apr 16 '16 at 19:14

# 8 instructions

My smallest solution to the Big Square II challenge is 8 lines of code. There's a simple loop which cycles through a table of 8 pixel locations.

; Big Square II in 0x08h instructions
; John Metcalf

PIX @18 002 000
MOV @18 @20 001
MOV @19 @18 008
FLP @16 @17 001
JMP @00 001 010
011 031 021 032
0D3 01D 0E3 01E


• Welcome to Programming Puzzles & Code Golf! Since this challenge scores by number of instructions, please include your instruction count in the post. With some more text, perhaps an explanation, you should be able to add the code and pass the spam filter. – Alex A. Apr 14 '16 at 19:57
• You really need to include the code. If the system isn't letting you, include a link to a GitHub Gist and a higher-rep user like myself can edit it in for you. – Mego Apr 14 '16 at 19:58
• Thanks for the suggestion. I've added an external link to the code. – impomatic Apr 14 '16 at 20:09
• I edited in the code for you as well as the number of instructions (assuming I'm interpreting your code correctly as 9 instructions). – Alex A. Apr 14 '16 at 20:10
• This comment belongs on the original question or on @orlp.'s answer but I haven't got enough reputation to comment there. I believe the scoring should be restated as "the lowest lines of code as counted by the Box-256 emulator" so tables of data, hand-assembled instructions and misaligned instructions count towards the total. – impomatic Apr 15 '16 at 5:44

# 11 instructions, 12 lines

PIX 011 002 000
JGR 00D @03 @00
MOV 000 @03 000
JGR 030 @06 @00
MOV 022 @01 000
MOV 02C @06 000
MOV 00B @0D 000
JMP @00 000 000
001 010 -01 -10


Any bonus for self-modification?

(Note the differences between the memory and the command line, specifically in locations @01 @06, @0D.)

I think my answer is probably what you were suggesting @orlp ?

I've used 3 instrutions, PIX, ADD and JMP, the rest are the co-ordinates (however the instructions and coordinates are spaced out below for easier reading):

000 000 000 000
000 000 000 000
PIX @2C 002 000
JMP @08 000 000
000 000 000 000
000 000 000 000
000 000 000 000
000 000 000 000
000 000 000 000
000 000 000 000
011 012 013 014
015 016 017 018
019 01A 01B 01C
01D 01E 021 022
023 024 025 026
027 028 029 02A
02B 02C 02D 02E
031 032 03D 03E
041 042 04D 04E
051 052 05D 05E
061 062 06D 06E
071 072 07D 07E
081 082 08D 08E
091 092 09D 09E
0B1 0B2 0BD 0BE
0C1 0C2 0CD 0CE
0D1 0D2 0D3 0D4
0D5 0D6 0D7 0D8
0D9 0DA 0DB 0DC
0DD 0DE 0E1 0E2
0E3 0E4 0E5 0E6
0E7 0E8 0E9 0EA
0EB 0EC 0ED 0EE


• Yes, this is why I don't think counting instructions is a good idea. – orlp Apr 15 '16 at 15:24
• @orlp - Can you expand a bit more on why? I want to gather up all the feedback from this question/challenge to make the next one better. – jwbensley Apr 17 '16 at 11:10
• Big data tables rake 3 instructions but many more bytes, but the 9 instruction solution spends around 8 bytes on tables. – CalculatorFeline Apr 17 '16 at 15:25