17

Choose your calling convention to put args where you want them. The language of your answer is asm (actually machine code), so treat it as part of a program written in asm, not C-compiled-for-x86. Your function doesn't have to be easily callable from C with any standard calling convention. That's a nice bonus if it doesn't cost you any extra bytes, though. ...


16

mov-immediate is expensive for constants This might be obvious, but I'll still put it here. In general it pays off to think about the bit-level representation of a number when you need to initialize a value. Initializing eax with 0: b8 00 00 00 00 mov $0x0,%eax should be shortened (for performance as well as code-size) to 31 c0 ...


16

C (gcc), 1381 1338 1255 1073 bytes Huge improvement thanks to ceilingcat and Rogem. #include<stdio.h> C*F="%02hhx ";m[256],p,a,x,z,n,c,e;g;*I(){R++p+m;}*A(){R*I()+m;}*X(){R*I()+m+x;}C*Q(){W(printf,m[g],1)exit(a);}C*(*L[])()={I,Q,A,Q,X,Q,Q,Q};l(C*i){R 254/p?*i=*L[m[p]&7]():*Q();}s(i){R 254/p?*L[m[p]&7]()=i:*Q();}q(){p>254?Q():++p;}C*y(){p+=...


13

171 bytes1 Wooohoooo! It took half the day, but it was fun... So, here it is. I think it conforms to the specs (wraparound of cell pointer, echo of characters on input, reading char by char, echo of input chars, ...), and it seems to actually work (well, I didn't try many programs, but given the simplicity of the language, the coverage isn't that bad, I ...


11

In a lot of cases, accumulator-based instructions (i.e. those that take (R|E)AX as the destination operand) are 1 byte shorter than general-case instructions; see this question on StackOverflow.


10

Create 3 zeroes with mul (then inc/dec to get +1 / -1 as well as zero) You can zero eax and edx by multiplying by zero in a third register. xor ebx, ebx ; 2B ebx = 0 mul ebx ; 2B eax=edx = 0 inc ebx ; 1B ebx=1 will result in EAX, EDX, and EBX all being zero in just four bytes. You can zero EAX and EDX in three bytes: ...


10

Use special-case short-form encodings for AL/AX/EAX, and other short forms and single-byte instructions Examples assume 32 / 64-bit mode, where the default operand size is 32 bits. An operand-size prefix changes the instruction to AX instead of EAX (or the reverse in 16-bit mode). inc/dec a register (other than 8-bit): inc eax / dec ebp. (Not x86-64: the ...


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


9

Dwarven Engineer A new and improved Dwarf. Wins against everything else submitted so far. The fancy corestep-optimized step size is probably overkill here. MOV bomb @aim aim MOV bomb @-6326 SUB step aim step JMZ #0 6328 MOV 0 1 bomb DAT 0 3164 Notable features include the fast bombing loop that ...


9

Turbo main add three target test jmz -1 @target bomb mov three @target sub j1 target mov jump @target sub j1 target mov copy @target sub j1 target two mov decr @target j1 jmp @target 1 target dat -8 -8 decr sub #two 3 copy mov 2 @2 jump jmp -2 0 three dat -9 -9 My 2nd ever CoreWar attempt. Designed ...


9

Graph View This can be used as a debugging tool. It displays the core and shows the location of the player. To use it you have to call it from code. I have also provided a modifed Game.java that automatically displays the GraphView. PhiNotPi and Ilmari Karonen recently changed the Controller. Ilmari Karonen has been kind enough to provide an updated GameView ...


9

Smallest runnable Mach-O has to be at least 0x1000 bytes. Because of XNU limitation, file has to be at least of PAGE_SIZE. See xnu-4570.1.46/bsd/kern/mach_loader.c, around line 1600. However, if we don't count that padding, and only count meaningful payload, then minimal file size runnable on macOS is 0xA4 bytes. It has to start with mach_header (or ...


9

APL (Dyalog Classic), 397 332 330 bytes thanks @Adám for -8 bytes f←{q←2⍴a x c←≡B←256⋄{0::m ⍺←(∇q∘←)0∘=,B≤+⍨ 30≤u←⌊8÷⍨b←p⊃m:∇p+←129-B|127-1⊃p↓m×⊃b⌽2/(,~,⍪)1,q,c p+←1 u=25:⍺x⊢←B|x+¯1*b u=26:∇c⊢←~2|b p+←≢o←m⊃⍨i←⍎'p⊃m+x'↑⍨1+8|b ⍎u⊃(,⍉'⍺ax⊢←o' '∇m[i]←ax'∘.~'xa'),5 4 2 3 2/'⍺⌽⊃'∘,¨'a⊢←2⊥(⍕⊃u⌽''∧∨≠'')/o a⊤⍨8⍴2' 'c(i⊃m)←u⌽d⊤(⌽d←u⌽2B)⊥u⌽o,c×u>10' 'c a⊢←2B⊤a+o+c'...


8

7 cycles, constant time Here's a solution based on my answer to this SO Question. It uses BSR to count how many bits are needed to hold the number. It looks up how many decimal digits needed to represent the largest number that many bits can hold. Then it subtracts 1 if the actual number is less than the nearest power of 10 with that many digits. ....


8

Dwarf A common and simple program that represents a dwarf throwing stones. It places a DAT instruction every four addresses. add 2 3 mov 2 @2 jmp -2 #4 dat #0 #4 EDIT: Fixes addressing. Apparently the addressing modes are different from the spec the OP linked to.


8

Subtract -128 instead of add 128 0100 81C38000 ADD BX,0080 0104 83EB80 SUB BX,-80 Samely, add -128 instead of subtract 128


8

7 instructions slt $t3, $t0, $t1 slt $t4, $t2, $t1 slt $t5, $t2, $t0 Compare all three pairs of values. xor $t3, $t3, $t4 movn $t0, $t1, $t3 $t1 is the median if it is greater than exactly one of the other values. xor $t5, $t5, $t4 movn $t0, $t2, $t5 $t2 is the median if it is less than exactly one of the other values. (Otherwise, $t0 is already the ...


7

I haven't tested this (VirtualBox doesn't pass through its virtual keyboard LEDs onto the physical keyboard, and I'm not on a PC I can reboot currently). But I think it should probably work and is probably quite minimal. There may be some additional setup that needs to be done on the keyboard controller for these commands to work. If so it would be ...


7

Evolved I honestly don't get how it works. It seems to construct its source code before doing anything. I would love it if someone gave me an explanation for how it works. After studying it, I found that it is simply a modified dwarf with an imp guard. Instead of bombing the enemies with DAT instructions, it shuffles the enemies code. It also bombs every two ...


7

JavaScript (ES6), 361 bytes Takes input as (memory)(program_counter), where memory is an Uint8Array. Outputs by modifying this array. M=>p=>{for(_='M[\u0011\u0011A]\u0010\u0010=\u000fc=\u000e,\u0011p]\f(n=\u000b128)\t=\u0010\b&=255\u0007,z=!(n\u0007),n&=\t;\u0006\u0006\u000b\u0005-\u0010,\u000en>=0\u0005\u0004\u0011c\b>>7,A]*2\u0005\...


6

FirstTimer If it does work, it should try to take position at the start of the core and create a defens main MOV 5 #0 ADD #data #main CMP #main #max JMP #0 0 JMP #main 0 MOV #data #100 ADD #data -1 JMP -2 0 data DAT 1 1 max DAT 8 3


6

Best case 8 cycles, Worst case 12 cycles Since it is not clear in the question, I am basing this off the Ivy Bridge latencies. The approach here is to use the bsr (bit scan reverse) instruction as a poor-man's log2(). The result is used as an index into a jump table which contains entries for bits 0 to 42. I am assuming that given that operation on 64bit ...


6

Janitor It should check if the following addresses are empty and if not it cleans them (thus, hopefully, erasing the opponent bot). Edit: This new version should be quicker (now that I understood the JMZ command and the @ reference correctly). JMZ 2 6 MOV 4 @-1 ADD 2 -2 JMP -3 0 DAT 0 1 DAT 0 0


6

CopyPasta Never participated to a CoreWar, this simple program is just trying to copy-paste himself and then execute the copy. It may not have the correct behavior, please tell me if it is the case. It is too pacifist and can't win in fact. MOV 6 0 MOV @-1 @-1 CMP @-2 3 JMP 4242 0 SUB -3 -4 JMP -4 0 DAT 0 4244


6

8 instructions slt $t4, $t2, $t1 movn $t3, $t1, $t4 movn $t1, $t2, $t4 movn $t2, $t3, $t4 Rearrange $t1 and $t2 so that $t1 ≤ $t2. slt $t3, $t2, $t0 slt $t4, $t0, $t1 movn $t0, $t2, $t3 movn $t0, $t1, $t4 If $t0 falls between $t1 and $t2, it is already the median. If it's outside that range, the one it lies beyond is the median.


5

GAS x86-64 for Linux (verified on GCC 10.1): 13 12 5 instructions 148 136 129 0 byte data section 298 274 260 51 49 byte source code Self-imposed rules/assumptions: No standard library (including printf and main) allowed. No .incbin allowed. This is commonly considered input in quine challenges. In a similar vein, I disallowed using the -D flag as this ...


5

Assuming registers are signed and/or wrapping 8 instructions: STO A 0x01 SUB A 0x01 SUB A 0x00 STO A 0x00 SUB A 0x00 SUB A 0x00 STO A 0x00 STO A 0x01 A 7-instruction version provided by lrn: STO A 0x01 SUB A 0x01 SUB A 0x00 STO A 0x01 SUB A 0x01 SUB A 0x01 STO A 0x01


5

ScanBomber Remove my comments before compiling. Scans for a while, then bombs when it finds a program. It probably will still lose to my Dwarf, though. scan add #eight #range ; scan jmz #scan @range sub #six #range fire mov #zero @range ; bombs away! (-6) add #two #range mov #zero @range add #two #range mov #zero @range add #two #range mov #zero @range ...


5

Han Shot First (v2) I figured the competition could use some more diversity, so here's my second entry: a one-shot CMP scanner. This is version 2, with improved anti-Imp defenses — it can now beat Imp, if only by just one point. It still loses to Dwarven Engineer, but beats everything else so far, putting it currently in tied first place. scan ...


Only top voted, non community-wiki answers of a minimum length are eligible