From 7446bcab45466fe6099ce0f956bed63236dceb64 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 21 Nov 2019 19:17:04 +0000 Subject: [PATCH] Update examples to new assembly syntax --- examples/bench.mimasm | 25 +++++++++++-------------- examples/call_ret.mimasm | 4 +--- examples/call_ret_stack.mimasm | 24 +++++++++++------------- examples/fib.mimasm | 22 +++++++++++----------- examples/jmp_to_address_in_acc.mimasm | 10 +++++----- examples/stack.mimasm | 22 +++++++++++----------- 6 files changed, 50 insertions(+), 57 deletions(-) diff --git a/examples/bench.mimasm b/examples/bench.mimasm index 33640cb..44500a2 100644 --- a/examples/bench.mimasm +++ b/examples/bench.mimasm @@ -1,19 +1,16 @@ -; The same as fib.mimasm, but with an increased number of fibonacci numbers to -; calculate. This file takes 11877318 steps to execute. +.reg IAR main +.reg SP -1 +.reg FP -1 -IAR = main -SP = 0xfffff -FP = 0xfffff +zero: .lit 0 ; Constant value for use with EQL +one: .lit 1 ; Constant value for use with EQL -zero: LIT 0 ; Constant value for use with EQL -one: LIT 1 ; Constant value for use with EQL - -tmp1: LIT 0 +tmp1: .lit 0 ; Variables for main -max-number: LIT 24 -current-number: LIT 0 -ptr: LDC number-array +max-number: .lit 24 +current-number: .lit 0 +ptr: LDC number-array main: ; Calls fib for every n from current-number to max-number and stores @@ -181,5 +178,5 @@ fib: RET ; Fibonacci numbers will be written here -300: -number-array: LIT 0 +.org 300 +number-array: diff --git a/examples/call_ret.mimasm b/examples/call_ret.mimasm index 1e68770..03f2762 100644 --- a/examples/call_ret.mimasm +++ b/examples/call_ret.mimasm @@ -1,6 +1,4 @@ -IAR = main -ACC = 0 -RA = 0 +.reg IAR main ; 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 diff --git a/examples/call_ret_stack.mimasm b/examples/call_ret_stack.mimasm index c0800ed..d560928 100644 --- a/examples/call_ret_stack.mimasm +++ b/examples/call_ret_stack.mimasm @@ -1,19 +1,17 @@ -IAR = main -ACC = 0 -RA = 0 -SP = 0xfffff +.reg IAR main +.reg SP -1 ; the last addressable address ; In this example, the stack pointer points to the next free address ; below the stack. The stack grows downwards from large to small ; addresses. The stack has no stack frames to simplify the program. -counter: LIT 0 +counter: .lit 0 -100: +.org 100 main: ; set counter bit 0 LDV counter - ADC 0x01 + ADC 0b00001 STV counter ; 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 LDV counter - ADC 0x02 + ADC 0b00010 STV counter HALT -200: +.org 200 sub-1: ; Set counter bit 2 LDV counter - ADC 0x04 + ADC 0b00100 STV counter ;; Store the current RA on the stack @@ -56,16 +54,16 @@ sub-1: ; Set counter bit 3 LDV counter - ADC 0x08 + ADC 0b01000 STV counter RET -300: +.org 300 sub-2: ; Set counter bit 4 LDV counter - ADC 0x10 + ADC 0b10000 STV counter RET diff --git a/examples/fib.mimasm b/examples/fib.mimasm index b1a7c2c..5f43af4 100644 --- a/examples/fib.mimasm +++ b/examples/fib.mimasm @@ -1,16 +1,16 @@ -IAR = main -SP = 0xfffff -FP = 0xfffff +.reg IAR main +.reg SP -1 +.reg FP -1 -zero: LIT 0 ; Constant value for use with EQL -one: LIT 1 ; Constant value for use with EQL +zero: .lit 0 ; Constant value for use with EQL +one: .lit 1 ; Constant value for use with EQL -tmp1: LIT 0 +tmp1: .lit 0 ; Variables for main -max-number: LIT 10 -current-number: LIT 0 -ptr: LDC number-array +max-number: .lit 10 +current-number: .lit 0 +ptr: LDC number-array main: ; Calls fib for every n from current-number to max-number and stores @@ -178,5 +178,5 @@ fib: RET ; Fibonacci numbers will be written here -300: -number-array: LIT 0 +.org 300 +number-array: diff --git a/examples/jmp_to_address_in_acc.mimasm b/examples/jmp_to_address_in_acc.mimasm index 60f2eda..4ec6ec7 100644 --- a/examples/jmp_to_address_in_acc.mimasm +++ b/examples/jmp_to_address_in_acc.mimasm @@ -1,14 +1,14 @@ -IAR = technique-1 +.reg IAR technique-1 ; This file demonstrates a few techniques for jumping to an address ; stored in the ACC. ; A few variables jump-instruction: JMP 0 -tmp: LIT 0 +tmp: .lit 0 ; Jumping by setting the RA and then returning -100: +.org 100 technique-1: LDC technique-2 STRA @@ -16,13 +16,13 @@ technique-1: ; Jumping by writing a JMP instruction to a memory location and then ; jumping to that (aka. almost self-modifying code) -200: +.org 200 technique-2: LDC end OR jump-instruction STV tmp JMP tmp -300: +.org 300 end: HALT diff --git a/examples/stack.mimasm b/examples/stack.mimasm index f1a04f0..d40bfe5 100644 --- a/examples/stack.mimasm +++ b/examples/stack.mimasm @@ -12,27 +12,27 @@ ; Functions take a fixed number of arguments. For this example, all ; values have a size of one word (24 bit). -IAR = main -SP = 0xfffff -FP = 0xfffff +.reg IAR main +.reg SP -1 +.reg FP -1 ; Temporary variables at a fixed memory location ; ; These are useful for commands like ADD, which need a fixed memory ; address. They are always under the complete control of the currently ; running function. -tmp1: LIT 0 -tmp2: LIT 0 -tmp3: LIT 0 -tmp4: LIT 0 -tmp5: LIT 0 +tmp1: .lit 0 +tmp2: .lit 0 +tmp3: .lit 0 +tmp4: .lit 0 +tmp5: .lit 0 -100: +.org 100 main: CALL caller HALT -200: +.org 200 caller: ;; 1. Initialisation @@ -121,7 +121,7 @@ caller: RET -300: +.org 300 callee: ; This callee doesn't really need its own stack since all ; calculations did fit into the temporary variables. I still created