Box-256 Assembly - BIG SQUARE II

5

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.

enter image description here

Rules:

  • Complete the BIG SQAURE II challenge in the Box-256 emulator (either on the website or download the program if you run Windows)
  • Post back here a screenshot of your working answer
  • 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).

jwbensley

Posted 2016-04-14T19:34:25.310

Reputation: 251

1I'm confused It says BIGSQUARE in the title but you should solve BIGSQUARE2?? – CalculatorFeline – 2016-04-15T01:06:31.310

@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 – 2016-04-15T07:33:47.907

How about we score by memory rows? – CalculatorFeline – 2016-04-15T15:20:38.300

Do we have to post a screenshot? – CalculatorFeline – 2016-04-15T19:52:45.540

@CatsAreFluffy - I think we should, reason being is that it shows that you have the correct answer/code without anyone having to run it. Site users may wish to vote on you answer but probably don't want to have to check them all by hand? – jwbensley – 2016-04-17T11:09:21.067

Or enter them in manually. That shouldn't be too hard now, but I definitely wouldn't want to enter 128 bytes of packed data... – CalculatorFeline – 2016-04-17T15:11:16.663

@CatsAreFluffy - I don't understand you most recent comment? – jwbensley – 2016-04-17T15:27:28.990

How else do you solve Mario? – CalculatorFeline – 2016-04-17T15:34:22.910

@CatsAreFluffy You asked about uploading a screen shot and I responded, why are you talking about solving Mario? – jwbensley – 2016-04-17T15:38:42.447

1@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 – 2016-04-19T10:49:40.270

1@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 – 2016-04-21T14:21:49.900

All good points, I have opened a Meta question so we can discuss in detail, we need to sort this out if we want to do more Box256 puzzles: http://meta.codegolf.stackexchange.com/questions/9012/how-to-score-box-256-answers

– jwbensley – 2016-04-23T13:07:25.340

Isn't the goal to solve it in the fewest cycles? Or should that be if the challenge is fastest-code? – mbomb007 – 2016-04-27T14:40:30.560

As per the link above, put your idea forward on the Meta link! :) – jwbensley – 2016-04-27T21:01:00.610

Please can you clarify the scoring (are we counting data lines as instructions) as the challenge is due to end within the next few hours and I'd like to change my answer if necessary. – impomatic – 2016-04-28T10:26:49.170

Under the rules this question was originally asked, I have marked @orlp's question as "answer" / "winner". Under the meta question regarding scoring Martin Büttner's answer was the most favoured so for future questions I aks I will use that scoring method. – jwbensley – 2016-05-13T07:57:27.877

Answers

4

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
07D 08D 09D 0AD
0BD 0CD 0ED 03E
04E 05E 06E 07E
08E 09E 0AE 0BE
0CE 000 000 000

screenshot

orlp

Posted 2016-04-14T19:34:25.310

Reputation: 37 067

Do you need JMP 002? – CalculatorFeline – 2016-04-15T01:13:35.040

1@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 – 2016-04-15T01:17:18.307

Hmm...Well how do you get the plaintext version of the programs? – CalculatorFeline – 2016-04-15T01:33:01.767

@orlp How did you come to the conclusion it's one instruction, from the original question:The winner will be the least amount of instructions used (just the instruction calls, either by name or opcode - You have used one instruction my name "JMP" and then many by opcode, have you not? – jwbensley – 2016-04-15T07:37:52.597

@CatsAreFluffy You can download the program as a windows executable and use CTRL+C/CTRL+V to copy paste to/from the editor to a notepad. See this URL: http://box-256.com/manual/

– jwbensley – 2016-04-15T07:38:53.520

@jwbensley There is one by name (which I thought the scoring was), but the same program can be done with just 3 instructions by opcode (PIX, ADD, JMP), while hardcoding the coordinates (mind you - these are not instruction opcodes). – orlp – 2016-04-15T07:41:18.067

@orlp If you can do it in three I suggest you update your answer to show that, and then you'd take the lead on this challenge! For now (I am the person that has down voted your answer because it does not illustrate that counting instructions is not a proper way of scoring - because it seems you have misunderstood the scoring. Please correct me if I am wrong. – jwbensley – 2016-04-15T08:14:50.797

For clarification I would say you answer is currently 3 instrutions, JMP, 0x72 (PIX), 0x13 (ADD) and 0x55 (JMP again, but as with the first JMP it's the same JMP using @ operator, so it compiles to the same opcode). – jwbensley – 2016-04-15T15:15:15.800

1JMP with @ ≠ JMP with 0 ≠ JMP with * – CalculatorFeline – 2016-04-15T15:20:09.517

You need to include the data in the line count otherwise you can solve every Box256 problem with the same three-five lines of code by just varying the data. – impomatic – 2016-04-16T19:04:32.763

@orlp can you beat (or match) 9 LOC if we score by LOC (as counted by Box256) instead of opcodes? – impomatic – 2016-04-16T19:09:01.107

1@impomatic Maybe, I haven't tried :) But LOC is still wrong. We should just score by bytes. – orlp – 2016-04-16T19:14:11.277

I think you should take a screenshot of the answer after executing it, not before. – CalculatorFeline – 2016-04-17T15:27:25.367

9

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
ADD @16 @18 @18
MOV @18 @20 001
MOV @19 @18 008
FLP @16 @17 001
JMP @00 001 010
011 031 021 032
0D3 01D 0E3 01E

BOX-256 Big Square II

impomatic

Posted 2016-04-14T19:34:25.310

Reputation: 341

1Welcome 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. – 2016-04-14T19:57:52.430

2

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 – 2016-04-14T19:58:34.983

Thanks for the suggestion. I've added an external link to the code. – impomatic – 2016-04-14T20:09:08.307

1I 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. – 2016-04-14T20:10:00.820

You can reply to people by using a @ sign and then their name, like @AlexA. – Rɪᴋᴇʀ – 2016-04-14T20:23:05.330

Going off of orlp's answer, I believe this is 5 instructions – Mego – 2016-04-15T01:06:39.827

2This 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 – 2016-04-15T05:44:11.660

@AlexA. I have a solution in 8 LOC now. Should I edit this answer or create a new one? – impomatic – 2016-04-19T12:21:22.087

@impomatic You should edit this post with your new solution. – Alex A. – 2016-04-19T14:04:52.600

3

11 instructions, 12 lines

PIX 011 002 000
ADD @01 @2C @01
ADD @03 001 @03
JGR 00D @03 @00
MOV 000 @03 000
ADD @06 001 @06
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.)

Note the differences between the memory and the command line.

Leaky Nun

Posted 2016-04-14T19:34:25.310

Reputation: 45 011

0

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
ADD 001 @09 @09
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
0A1 0A2 0AD 0AE
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

enter image description here

jwbensley

Posted 2016-04-14T19:34:25.310

Reputation: 251

Yes, this is why I don't think counting instructions is a good idea. – orlp – 2016-04-15T15:24:34.120

@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 – 2016-04-17T11:10:02.677

Big data tables rake 3 instructions but many more bytes, but the 9 instruction solution spends around 8 bytes on tables. – CalculatorFeline – 2016-04-17T15:25:39.403