Blame
|
1 | # Assembly Language |
||||||
| 2 | ||||||||
| 3 | This page describes how gcc passes arguments, which is required when accessing those arguments from inside a piece of assembly. |
|||||||
| 4 | ||||||||
| 5 | Here's an example of how gcc compiled a function |
|||||||
| 6 | ``` |
|||||||
| 7 | 00c06950 <zobbo>: |
|||||||
| 8 | ||||||||
| 9 | int __attribute__ ((noinline)) zobbo(uint8_t drive_num, uint32_t block_num, uint8_t *buffer) { |
|||||||
| 10 | drive_num++; |
|||||||
| 11 | ||||||||
| 12 | if (drive_num == 42) { |
|||||||
| 13 | c06950: 0c2f 0029 0007 cmpib #41,%sp@(7) |
|||||||
| 14 | c06956: 671e beqs c06976 <zobbo+0x26> |
|||||||
| 15 | return NOT_OK; |
|||||||
| 16 | } |
|||||||
| 17 | ||||||||
| 18 | block_num--; |
|||||||
| 19 | ||||||||
| 20 | if (block_num == 99) { |
|||||||
| 21 | c06958: 7064 moveq #100,%d0 |
|||||||
| 22 | c0695a: b0af 0008 cmpl %sp@(8),%d0 |
|||||||
| 23 | c0695e: 670e beqs c0696e <zobbo+0x1e> |
|||||||
| 24 | errno = 99; |
|||||||
| 25 | return NOT_OK; |
|||||||
| 26 | } |
|||||||
| 27 | ||||||||
| 28 | if (*buffer == '!') { |
|||||||
| 29 | c06960: 206f 000c moveal %sp@(12),%a0 |
|||||||
| 30 | c06964: 0c10 0021 cmpib #33,%a0@ |
|||||||
| 31 | c06968: 57c0 seq %d0 |
|||||||
| 32 | c0696a: 49c0 extbl %d0 |
|||||||
| 33 | return NOT_OK; |
|||||||
| 34 | } |
|||||||
| 35 | ||||||||
| 36 | return OK; |
|||||||
| 37 | } |
|||||||
| 38 | c0696c: 4e75 rts |
|||||||
| 39 | errno = 99; |
|||||||
| 40 | c0696e: 7063 moveq #99,%d0 |
|||||||
| 41 | c06970: 23c0 0000 1160 movel %d0,1160 <errno> |
|||||||
| 42 | return NOT_OK; |
|||||||
| 43 | c06976: 70ff moveq #-1,%d0 |
|||||||
| 44 | } |
|||||||
| 45 | c06978: 4e75 rts |
|||||||
| 46 | ``` |
|||||||