PicoBlaze Simulator in JavaScript
-
- Master of the Forum
- Posts: 1452
- Joined: Tue Oct 27, 2015 3:46 pm
- Diet: Vegan
Re: PicoBlaze Simulator in JavaScript
For the past few days, I've been working intensely on the PicoBlaze assembler. I've added the support for `?:` operator in the preprocessor, so that it can be used in the constants. And I ran into a problem: how can the tokenizer know, when it sees `:`, whether that `:` is a part of a label (so that it's not a separate token) or whether it's a part of the `?:` operator (so that it is a separate token). I solved it by adding a rule that every `:` followed by a new-line token or preceded by a new-line token exactly two tokens ago is a part of a label. However, that's not really a nice solution. I asked on Internet forums how C compilers tend to solve that problem, and the general consensus seems to be that the tokenizer isn't even supposed to know that, that it's the parser's job to determine that. But how do I implement that in my parser? I asked a question about that on StackExchange: https://langdev.stackexchange.com/q/4071/330
-
- Master of the Forum
- Posts: 1452
- Joined: Tue Oct 27, 2015 3:46 pm
- Diet: Vegan
Re: PicoBlaze Simulator in JavaScript
The day before yesterday, I added the support for octal numbers in the constants to my PicoBlaze assembler, that octal numbers can be written with `'o` at the end. Not like in JavaScript, where they start with `0` or `0o`, but them ending in `'o` makes sense in PicoBlaze assembler because there the decimal constants are written with `'d` at the end, and binary constants are written with `'b` at the end. And I have also written an assembly language program that converts binary numbers into octal numbers:
Code: Select all
;This is a program which converts binary
;numbers entered using the switches to
;octal, and displays the octal numbers
;using the 7-segment displays.
address 0 ;That's a message to the
;preprocessor of the assembler
;to start assembling from the
;memory address 0. Every
;PicoBlaze program starts like
;that.
input s0, 0 ;The switches are at the
;input address 0.
;The octal numbers that fit in 8 bits
;can be up to 3 digits long. I think
;it's easier to deal with the first
;digit separately, storing it in the
;register sc.
load sc, 0
compare s0, 300'o
jump c, less_than_300
load sc, 3
sub s0, 300'o
less_than_300:
compare s0, 200'o
jump c, less_than_200
load sc, 2
sub s0, 200'o
less_than_200:
compare s0, 100'o
jump c, less_than_100
load sc, 1
sub s0, 100'o
less_than_100:
;Then we divide the number entered
;using the switches by 8. The result
;of the division will be stored in s1,
;and the modulo of the division (the
;last octal digit of the number) will
;be stored in s0.
load s1, 0
beginning_of_the_first_loop:
compare s0, 8
jump c, end_of_the_first_loop
add s1, 1
sub s0, 8
jump beginning_of_the_first_loop
end_of_the_first_loop:
;Then we need to multiply s1 by 16,
;because the seven-segment displays
;display hexadecimal numbers.
load sa, 0
load sb, 16'd
beginning_of_the_second_loop:
add sa, s1
sub sb, 1
jump nz, beginning_of_the_second_loop
;Now the second hexadecimal digit of
;sa is 0. Let's add the s0 (the modulo)
;to it. Then, let's display sa and sc on
;the seven-segment displays.
add sa, s0
output sa, 2
output sc, 1
;Then run into an infinite loop...
jump 0 ;You can add a breakpoint here.