Thread: Assembly
View Single Post
evan
Formerly CoachKrzyzewski
 
Join Date: Jan 2006
Location: Charlottesville, VA
Send a message via AIM to evan  
2010-03-25, 23:37

Quote:
Originally Posted by scratt View Post
Nice work. There is nothing like coding in ASM to put hairs on your chest!!

What flavour of assembly? i386, ARM... ?
IBCM

Here's my bubbles sort - it sorts the array that is the last 5 lines of code. obviously you could change N and a[] and put in a different array and (hopefully) it would still work.

Code:
C00A 00 jmp start skip around the variables 0000 01 i dw 0 int i 0000 02 j dw 0 int j 0043 03 a dw 0 int a[] - array of 5 [ 5, 4, 3, 2, 1] 0005 04 N dw 0 int N 0001 05 one dw 1 3000 06 loadit dw 3000 6000 07 subit dw 6000 0000 08 temp dw 0 4000 09 stoit dw 4000 3004 0A oloop load n if (j >= N) goto xit 6002 0B sub j E023 0C jmpl xit jump to exit if N < j D023 0D jmpe xit jump to exit if N == j 3004 0E iloop load n if (i >= N-1) goto end of outterloop 6001 0F sub i 6005 10 sub 1 E03D 11 jmpl xit jump to end of iloop if N < i D03D 12 jmpe xit jump to end of iloop if N == i 3006 13 load loadit form instruction to load a[i] 5003 14 add a 5001 15 add i 5005 16 add 1 401C 17 store doit plant instruction into program 3007 18 load subit form instruction to load a[i] 5003 19 add a 5001 1A add i 401D 1B store doit2 plant instructions 0000 1C doit load doit 0000 1D doit2 dw 0 E024 1E jmpl swap goto swap if a[i]>a[i+1] 3001 1F load i i += 1 5005 20 add one 4001 21 store i C00E 22 jmp loop goto iloop 0000 23 xit 3006 24 swap load loadit form instructions to put a[i] in temp----- 5003 25 add a 5001 26 add i 4028 27 store doit3 plant instructions 0000 28 doit3 dw 0 4008 29 store a[i] storing in temp ----------------- 3009 2A load stoit form instructions to put a[i+1] in a[i] 5003 2B add a 5001 2C add i 4034 2D store doit4 plant instructions to store in a[i+1] 3006 2E load loadit 5005 2F add 1 5003 30 add a 5001 31 add i 4033 32 store doit5 0000 33 doit5 dw 0 0000 34 doit4 dw 0 put a[i+1] into a[i]------------------ 3009 35 load stoit form instructions to put temp in a[i+1] 5005 36 add 1 5003 37 add a 5001 38 add i 403B 39 store doit6 3008 3A load temp 0000 3B doit6 dw 0 puts temp in [a+1] C01F 3C jmp back into loop 3002 3D load j i += 1 5005 3E add one 4002 3F store j 3050 40 load zero 4001 41 store i C00A 42 jmp loop goto loop 0005 0004 0003 0002 0001
the first four digits of each line is all the compiler reads, the rest is just comments to make it readable.

when I finally got it it was awesome. One of the more rewarding programming experiences I've had (and last week we made our own hash tree! - in C++, not assembly )
  quote