Machine code: Difference between revisions
→{{header|Action!}}
m (Applesoft BASIC) |
Puppydrum64 (talk | contribs) |
||
Line 21:
* Execute the machine code with the following arguments: unsigned-byte argument of value 7; unsigned-byte argument of value 12; The result would be 19.
* Perform any clean up actions that are appropriate for your chosen language (free the pointer or memory allocations, etc.)
=={{header|6502 Assembly}}==
We'll execute the following program:
<lang 6502asm>LDA #$07
CLC
ADC #$0C
RTS</lang>
<lang 6502asm>main:
LDX #$00 ;initialize array offset to 0
LDA #$A9 ;LDA #immediate
STA Array,x ;store at offset 0
INX ;next offset
LDA #$07 ;first parameter
STA Array,x ;store at offset 1
INX ;next offset
LDA #$18 ;CLC
STA Array,x ;store at offset 2
INX ;next offset
LDA #$69 ;ADC #immediate
STA Array,x ;store at offset 3
INX ;next offset
LDA #$0C ;second parameter
STA Array,x ;store at offset 4
INX ;next offset
LDA #$60 ;RTS
STA Array,x ;store at offset 5
JMP Array ;assuming we used a JSR to get to main, the RTS at the end of this RAM will return us back to BASIC.
;if array is directly underneath this statement, we can actually omit this JMP entirely
;and execution will simply fall through to the array.
Array:
byte 0,0,0,0,0,0</lang>
If you're going to do this in actual programming (which is somewhat common on 8-bit computers for quick interrupt handling), it may be a good idea to know ahead of time the maximum size of your RAM area for machine code and fill it with return statements to avoid crashing.
|