Update examples to new assembly syntax
This commit is contained in:
parent
ae0c31d83a
commit
7446bcab45
6 changed files with 50 additions and 57 deletions
|
|
@ -1,19 +1,16 @@
|
||||||
; The same as fib.mimasm, but with an increased number of fibonacci numbers to
|
.reg IAR main
|
||||||
; calculate. This file takes 11877318 steps to execute.
|
.reg SP -1
|
||||||
|
.reg FP -1
|
||||||
|
|
||||||
IAR = main
|
zero: .lit 0 ; Constant value for use with EQL
|
||||||
SP = 0xfffff
|
one: .lit 1 ; Constant value for use with EQL
|
||||||
FP = 0xfffff
|
|
||||||
|
|
||||||
zero: LIT 0 ; Constant value for use with EQL
|
tmp1: .lit 0
|
||||||
one: LIT 1 ; Constant value for use with EQL
|
|
||||||
|
|
||||||
tmp1: LIT 0
|
|
||||||
|
|
||||||
; Variables for main
|
; Variables for main
|
||||||
max-number: LIT 24
|
max-number: .lit 24
|
||||||
current-number: LIT 0
|
current-number: .lit 0
|
||||||
ptr: LDC number-array
|
ptr: LDC number-array
|
||||||
|
|
||||||
main:
|
main:
|
||||||
; Calls fib for every n from current-number to max-number and stores
|
; Calls fib for every n from current-number to max-number and stores
|
||||||
|
|
@ -181,5 +178,5 @@ fib:
|
||||||
RET
|
RET
|
||||||
|
|
||||||
; Fibonacci numbers will be written here
|
; Fibonacci numbers will be written here
|
||||||
300:
|
.org 300
|
||||||
number-array: LIT 0
|
number-array:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
IAR = main
|
.reg IAR main
|
||||||
ACC = 0
|
|
||||||
RA = 0
|
|
||||||
|
|
||||||
; This CALL/RET example does not use any sort of stack, and thus can
|
; This CALL/RET example does not use any sort of stack, and thus can
|
||||||
; only go 1 call deep. Nevertheless, it demonstrates how the CALL and
|
; only go 1 call deep. Nevertheless, it demonstrates how the CALL and
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
IAR = main
|
.reg IAR main
|
||||||
ACC = 0
|
.reg SP -1 ; the last addressable address
|
||||||
RA = 0
|
|
||||||
SP = 0xfffff
|
|
||||||
|
|
||||||
; In this example, the stack pointer points to the next free address
|
; In this example, the stack pointer points to the next free address
|
||||||
; below the stack. The stack grows downwards from large to small
|
; below the stack. The stack grows downwards from large to small
|
||||||
; addresses. The stack has no stack frames to simplify the program.
|
; addresses. The stack has no stack frames to simplify the program.
|
||||||
|
|
||||||
counter: LIT 0
|
counter: .lit 0
|
||||||
|
|
||||||
100:
|
.org 100
|
||||||
main:
|
main:
|
||||||
; set counter bit 0
|
; set counter bit 0
|
||||||
LDV counter
|
LDV counter
|
||||||
ADC 0x01
|
ADC 0b00001
|
||||||
STV counter
|
STV counter
|
||||||
|
|
||||||
; Since we're top-level, we don't need to (re-)store our RA when calling
|
; Since we're top-level, we don't need to (re-)store our RA when calling
|
||||||
|
|
@ -21,16 +19,16 @@ main:
|
||||||
|
|
||||||
; set counter bit 1
|
; set counter bit 1
|
||||||
LDV counter
|
LDV counter
|
||||||
ADC 0x02
|
ADC 0b00010
|
||||||
STV counter
|
STV counter
|
||||||
|
|
||||||
HALT
|
HALT
|
||||||
|
|
||||||
200:
|
.org 200
|
||||||
sub-1:
|
sub-1:
|
||||||
; Set counter bit 2
|
; Set counter bit 2
|
||||||
LDV counter
|
LDV counter
|
||||||
ADC 0x04
|
ADC 0b00100
|
||||||
STV counter
|
STV counter
|
||||||
|
|
||||||
;; Store the current RA on the stack
|
;; Store the current RA on the stack
|
||||||
|
|
@ -56,16 +54,16 @@ sub-1:
|
||||||
|
|
||||||
; Set counter bit 3
|
; Set counter bit 3
|
||||||
LDV counter
|
LDV counter
|
||||||
ADC 0x08
|
ADC 0b01000
|
||||||
STV counter
|
STV counter
|
||||||
|
|
||||||
RET
|
RET
|
||||||
|
|
||||||
300:
|
.org 300
|
||||||
sub-2:
|
sub-2:
|
||||||
; Set counter bit 4
|
; Set counter bit 4
|
||||||
LDV counter
|
LDV counter
|
||||||
ADC 0x10
|
ADC 0b10000
|
||||||
STV counter
|
STV counter
|
||||||
|
|
||||||
RET
|
RET
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
IAR = main
|
.reg IAR main
|
||||||
SP = 0xfffff
|
.reg SP -1
|
||||||
FP = 0xfffff
|
.reg FP -1
|
||||||
|
|
||||||
zero: LIT 0 ; Constant value for use with EQL
|
zero: .lit 0 ; Constant value for use with EQL
|
||||||
one: LIT 1 ; Constant value for use with EQL
|
one: .lit 1 ; Constant value for use with EQL
|
||||||
|
|
||||||
tmp1: LIT 0
|
tmp1: .lit 0
|
||||||
|
|
||||||
; Variables for main
|
; Variables for main
|
||||||
max-number: LIT 10
|
max-number: .lit 10
|
||||||
current-number: LIT 0
|
current-number: .lit 0
|
||||||
ptr: LDC number-array
|
ptr: LDC number-array
|
||||||
|
|
||||||
main:
|
main:
|
||||||
; Calls fib for every n from current-number to max-number and stores
|
; Calls fib for every n from current-number to max-number and stores
|
||||||
|
|
@ -178,5 +178,5 @@ fib:
|
||||||
RET
|
RET
|
||||||
|
|
||||||
; Fibonacci numbers will be written here
|
; Fibonacci numbers will be written here
|
||||||
300:
|
.org 300
|
||||||
number-array: LIT 0
|
number-array:
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
IAR = technique-1
|
.reg IAR technique-1
|
||||||
|
|
||||||
; This file demonstrates a few techniques for jumping to an address
|
; This file demonstrates a few techniques for jumping to an address
|
||||||
; stored in the ACC.
|
; stored in the ACC.
|
||||||
|
|
||||||
; A few variables
|
; A few variables
|
||||||
jump-instruction: JMP 0
|
jump-instruction: JMP 0
|
||||||
tmp: LIT 0
|
tmp: .lit 0
|
||||||
|
|
||||||
; Jumping by setting the RA and then returning
|
; Jumping by setting the RA and then returning
|
||||||
100:
|
.org 100
|
||||||
technique-1:
|
technique-1:
|
||||||
LDC technique-2
|
LDC technique-2
|
||||||
STRA
|
STRA
|
||||||
|
|
@ -16,13 +16,13 @@ technique-1:
|
||||||
|
|
||||||
; Jumping by writing a JMP instruction to a memory location and then
|
; Jumping by writing a JMP instruction to a memory location and then
|
||||||
; jumping to that (aka. almost self-modifying code)
|
; jumping to that (aka. almost self-modifying code)
|
||||||
200:
|
.org 200
|
||||||
technique-2:
|
technique-2:
|
||||||
LDC end
|
LDC end
|
||||||
OR jump-instruction
|
OR jump-instruction
|
||||||
STV tmp
|
STV tmp
|
||||||
JMP tmp
|
JMP tmp
|
||||||
|
|
||||||
300:
|
.org 300
|
||||||
end:
|
end:
|
||||||
HALT
|
HALT
|
||||||
|
|
|
||||||
|
|
@ -12,27 +12,27 @@
|
||||||
; Functions take a fixed number of arguments. For this example, all
|
; Functions take a fixed number of arguments. For this example, all
|
||||||
; values have a size of one word (24 bit).
|
; values have a size of one word (24 bit).
|
||||||
|
|
||||||
IAR = main
|
.reg IAR main
|
||||||
SP = 0xfffff
|
.reg SP -1
|
||||||
FP = 0xfffff
|
.reg FP -1
|
||||||
|
|
||||||
; Temporary variables at a fixed memory location
|
; Temporary variables at a fixed memory location
|
||||||
;
|
;
|
||||||
; These are useful for commands like ADD, which need a fixed memory
|
; These are useful for commands like ADD, which need a fixed memory
|
||||||
; address. They are always under the complete control of the currently
|
; address. They are always under the complete control of the currently
|
||||||
; running function.
|
; running function.
|
||||||
tmp1: LIT 0
|
tmp1: .lit 0
|
||||||
tmp2: LIT 0
|
tmp2: .lit 0
|
||||||
tmp3: LIT 0
|
tmp3: .lit 0
|
||||||
tmp4: LIT 0
|
tmp4: .lit 0
|
||||||
tmp5: LIT 0
|
tmp5: .lit 0
|
||||||
|
|
||||||
100:
|
.org 100
|
||||||
main:
|
main:
|
||||||
CALL caller
|
CALL caller
|
||||||
HALT
|
HALT
|
||||||
|
|
||||||
200:
|
.org 200
|
||||||
caller:
|
caller:
|
||||||
;; 1. Initialisation
|
;; 1. Initialisation
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ caller:
|
||||||
|
|
||||||
RET
|
RET
|
||||||
|
|
||||||
300:
|
.org 300
|
||||||
callee:
|
callee:
|
||||||
; This callee doesn't really need its own stack since all
|
; This callee doesn't really need its own stack since all
|
||||||
; calculations did fit into the temporary variables. I still created
|
; calculations did fit into the temporary variables. I still created
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue