So I've written and manually "assembled" the following piece of asm using the AVR instruction set PDF from their website.
ldi r17, 0 ; 1110 0000 0001 0000
ldi r18, 3 ; 1110 0000 0010 0011
ldi r16, 0 ; 1110 0000 0000 0000
loop:
sbrc r18, 0 ; 1111 1101 0010 0000
add r16, r17 ; 0000 1111 0000 0001
lsl r17 ; 0000 1100 0001 0001
lsr r18 ; 1001 0101 0010 0110
brne loop ; 1111 01-- ---- ----
again:
rjmp again ; 1001 010- ---- 110-
; ---- ---- ---- ----
However when I actually assemble the file with Avra and dump the resulting .hex
file in binary I get this:
0011101000110000
0011001000110000
0011000000110000
0011000000110000
0011001000110000
0011000000110000
0011000001000110
0100001100001101
0000101000111010
0011000100110000
0011000000110000
0011000000110000
0011000000110000
0011000100110000
0100010100110000
0011001000110011
0100010100110000
0011000000110000
0100010100110000
0011001000110000
0100011001000100
0011000000110001
0011000001000110
0011000100110001
0011000001000110
0011001000110110
0011100100110101
0100010000111001
0100011000110111
0011010000110101
0000110100001010
0011101000110000
0011001000110000
0011000000110001
0011000000110000
0011000001000110
0100011001000011
0100011000110010
0011000000001101
0000101000111010
0011000000110000
0011000000110000
0011000000110000
0011000000110001
0100011001000110
0000110100001010
0000110100001010
When I flash the hex file to an Arduino it runs fine (the given asm doesn't give any output, but I've made asm to turn off the led and such, which worked fine so I'm assuming this does as well). Can somebody tell me what is going on here? Why are there so many extra bits and why can't I find any of my instructions?
I don't know why you decided to take ASCII-text ".hex" file and convert it into strings of binary digits, unless you wanted to make our life harder.
I have converted those cryptic lines back to the .hex
source:
:020000020000FC
:1000000010E023E000E020FD010F110F2695D9F745
:02001000FFCF20
:00000001FF
what is the ".hex" file - you can read, for example, in Wikipedia.
First line :02 0000 02 0000 FC sets initial segment offset (0).
Second line :10 0000 00 10E023E000E020FD010F110F2695D9F7 45 - it is where your code is contained. You can convert the highlighted string into a binary, if you want:
1110000000010000
1110000000100011
1110000000000000
1111110100100000
0000111100000001
0000111100010001
1001010100100110
1111011111011001
As you can see all your code is there and intact.