Page 1 of 1
Kowalski Simulator
Posted: Fri Sep 16, 2011 8:00 pm
by BigDumbDinosaur
In another post, I eluded to some undocumented functions within Michal Kowalski's 65xx simulator. In addition to the usual expression operators found in any good assembler, the simulator supports a number of logical operators that may be useful with various bit-twiddling functions. All of these are assembly-time functions:
- & - Bitwise AND
Usage: <expr1> & <expr2>
Effect: ANDs <expr1> with <expr2>
Example: MASK = @00001111 & @00000010
Result: MASK = @00000010
- | - Bitwise OR
Usage: <expr1> | <expr2> (| is the UNIX pipe symbol)
Effect: ORs <expr1> with <expr2>
Example: MASK = @00001111 | @11110000
Result: MASK = @11111111
- ^ - Bitwise exclusive-OR (XOR)
Usage: <expr1> ^ <expr2>
Effect: XORs <expr1> with <expr2>
Example: MASK = @01011010 ^ @11111111
Result: MASK = @10100101
- ! - NOT
Usage: !<expr>; ! is a unary operator
Effect: Negates <expr>
Example: FLAG = !0
Result: FLAG = 1
- << - Left shift
Usage: <expr> << N
Effect: Left shifts <expr> N times; N may be any valid integer expression
Example: MASK = @00000001 << 4
Result: MASK = @00010000
- >> - Right shift
Usage: <expr> >> N
Effect: Right shifts <expr> N times; N may be any valid integer expression
Example: MASK = @10000000 >> 1
Result: MASK = @01000000
- == - Is equal to
Usage: <expr1> == <expr2>
Effect: Checks for equality
Example: FLAG = 4 == 3
Result: FLAG = 1 (false)
Example: FLAG = 4 == 4
Result: FLAG = 0 (true)
- != - Is not equal to
Usage: <expr1> != <expr2>
Effect: Checks for inequality
Example: FLAG = 4 != 3
Result: FLAG = 0 (true)
Example: FLAG = 4 != 4
Result: FLAG = 1 (false)
- % - Modulo
Usage: <expr1> % <expr2>
Effect: Returns the remainder of <expr1> / <expr2>
Example: FLAG = 12 % 5
Result: FLAG = 2
- ~ - Ones complement
Usage: ~<expr>; ~ is a unary operator
Effect: Computes ones complement of <expr>
Example: STEP = ~$01
Result: STEP = $FE
The following code illustrates how this stuff works. Paste it into a new code window in the simulator, assemble and press [Alt-6] to view the results.
Code: Select all
.opt proc65c02,caseinsensitive
;
test0001 =@00001111
test0002 =test0001 << 4 ;shift left 4 times
test0003 =test0002 >> 4 ;shift right 4 times, will be same as test0001
test0004 =test0001 & test0002 ;bitwise AND, will be zero
test0005 =test0001 | test0002 ;bitwise OR
test0006 =@01011010^test0005 ;bitwise XOR
test0007 =!0 ;logical NOT
test0008 =4 == 3 ;equality test
test0009 =4 == 4 ;equality test
test0010 =4 != 3 ;inequality test
test0011 =4 != 4 ;inequality test
test0012 =12 % 5 ;modulo
test0013 =~1 ;1s complement
;
.end
Edit: made some corrections
Re: Kowalski Simulator
Posted: Sat Sep 17, 2011 7:19 pm
by fachat
In another post, I eluded to some undocumented functions within Michal
Kowalski's 65xx simulator. In addition to the usual expression operators found in any good assembler, the simulator supports a number of logical operators that may be useful with various bit-twiddling functions. All of these are assembly-time functions:
All of them except "%" modulo (and maybe "~" two's complement, don't remember that) are also supported by the xa65 cross assembler :-)
Also works at compile time.
André
Re: Kowalski Simulator
Posted: Wed Sep 12, 2012 2:59 pm
by Dr Jefyll
Here's an error to report, and also a few questions for BDD, or anyone, regarding the
Kowalski assembler:
First: Will it let you create local labels, and how is that done? Example:
Code: Select all
...
...
inc LS_byte
bne doIhavetomakeupanameforthis
inc MS_byte
doIhavetomakeupanameforthis
...
BDD, thanks for the info you've posted here and on
your web site re this assembler. In fact I notice there's quite a lot of
Kowalski assembler discussion here in the
Emulation and Simulation section. Some but not all of the info is reproduced on your site -- would you be interested in going further? Or perhaps a new topic
in the Programming section might be better -- more interactive, I mean. In any case, it'd be a real asset to users if the material could be collected in one place. Even some of the basic stuff... For example, we all know $ prefixes a hex number, but offhand I don't recall how to invoke binary notation, or -- heaven forbid -- octal!!
Finally, something's not right in your post above. The two's complement of 1 is $FF, not $FE. Is that a teeny typo on your part (you meant to say the ~ tilde symbol represents
one's complement), or is it a bug in the assembler (which does indeed evaluate ~1 as $FE)?
thanks,
Jeff
EDIT: I deleted my question about the directives. Info about directives pops up on-screen in the simulator's editor window; all you do is set your cursor on a directive in your source code, and... shazam! (I overlooked this excellent feature because, instead of Kowalkski's editor, I usually use the source-code editor
Notepad++ -- also excellent, and free.)
Re: Kowalski Simulator
Posted: Wed Sep 12, 2012 6:37 pm
by BigDumbDinosaur
Here's an error to report, and also a few questions for BDD, or anyone, regarding the
Kowalski assembler:
First: Will it let you create local labels, and how is that done? Example:
Code: Select all
...
...
inc LS_byte
bne doIhavetomakeupanameforthis
inc MS_byte
doIhavetomakeupanameforthis
...
You can define a label as local by prefixing it with a period, e.g.:
Code: Select all
...
...
inc LS_byte
bne .0000010
;
inc MS_byte
;
.0000010 beq .0000020
...etc
The scope of local labels is bounded by the conventional labels that start and end the section. Needless to say, local labels are quite useful inside of subroutines and in macro definitions.
BDD, thanks for the info you've posted here and on
your web site re this assembler. In fact I notice there's quite a lot of
Kowalski assembler discussion here in the
Emulation and Simulation section. Some but not all of the info is reproduced on your site -- would you be interested in going further? Or perhaps a new topic
in the Programming section might be better -- more interactive, I mean. In any case, it'd be a real asset to users if the material could be collected in one place. Even some of the basic stuff... For example, we all know $ prefixes a hex number, but offhand I don't recall how to invoke binary notation, or -- heaven forbid -- octal!!
You may define a binary value with @, e.g.:
Note that this is non-standard syntax—the recommended symbol is %. To my knowledge, there is no support for octal values in the Kowalski simulator.
Finally, something's not right in your post above. The two's complement of 1 is $FF, not $FE. Is that a teeny typo on your part (you meant to say the ~ tilde symbol represents one's complement), or is it a bug in the assembler (which does indeed evaluate ~1 as $FE)?
I'll have to check it out. I went by what the assembler generated and didn't think to manually code and run it on POC to check the result.
EDIT: I deleted my question about the directives. Info about directives pops up on-screen in the simulator's editor window; all you do is set your cursor on a directive in your source code, and... shazam! (I overlooked this excellent feature because, instead of Kowalkski's editor, I usually use the source-code editor
Notepad++ -- also excellent, and free.)
Context-sensitive help also works on mnemonics. Be aware, however, that the Kowalski simulator simulates the Rockwell version of the 65C02.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 12:26 am
by Dr Jefyll
You can define a label as local by prefixing it with a period
That's good to know, too, but it isn't the information I was seeking. Probably I'm using the wrong terminology -- "local" -- so, without using that term, I'll explain more carefully.
I'm talking about a convenient feature that I first learned using the TASM and MASM x86 assemblers. In a situation like this...
Code: Select all
...
...
inc LS_byte ;inc the LS byte
bne doIhavetomakeupanameforthis ;Result zero? Skip the increment on the MS byte
inc MS_byte
doIhavetomakeupanameforthis
...
the branch is a short one, and easy to understand. For such a trivial situation, some folks take the view that
it's un-necessary for the programmer to devote time to creating a unique label name for the branch target. Some disagree, perhaps. Anyway, the
optional time-saving alternative was to use the handy MASM/TASM feature, which let you code something like this:
Code: Select all
...
...
inc LS_byte ;inc the LS byte
bne @F ;Result zero? Skip the increment on the MS byte
inc MS_
F@
...
The assembler recognizes
@F as denoting a
Forward branch to
the closest location marked F@.
Backward branches used @
B and
B@ in the same way. (I just made up the @ thing, having forgotten the actual character sequence.) These little placeholder labels could be used repeatedly, without confusion and without any "not unique" error message. I thought the idea was a pretty cool time-saver, and wondered if
Kowalski included it. Now I'm wondering what to call it, too!
J.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 1:14 am
by BigDumbDinosaur
Code: Select all
...
...
inc LS_byte ;inc the LS byte
bne @F ;Result zero? Skip the increment on the MS byte
inc MS_
F@
...
The Kowalski assembler doesn't support that idiom. Best you can do is local labels like I described above.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 3:51 am
by GARTHWILSON
Why not
structure macros. No label needed.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 4:27 am
by BigDumbDinosaur
I figured you would suggest that! 
Code: Select all
incmem16 .macro .ad ;16 bit memory increment
inc .ad
bne .0000010
inc .ad+1
.0000010 ;placeholder
.endm
Just call the above with incmem16 <addr>, where <addr> is the LSB of the location to increment. The local label .0000010 will be invisible outside of the macro invocation.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 5:06 am
by GARTHWILSON
That kind of macro is definitely valid and makes for fewer lines to look at, but there will be countless other needs for branches where it would be nice to avoid adding a label, especially when you can't think up a valid, meaningful name (hence the "doIhavetomakeupanameforthis"). Before the structure macros, I had tons of labels like aafd1 or mcp2, abbreviating the name of the routine they're in and then numbering the branch destinations within the routine.
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 1:48 pm
by Dr Jefyll
Structured conditionals are the norm for
Bill Ragsdale's RPN assembler. But, for a mainstream assembler, I wouldn't have thought of attempting to provide structured conditionals via macros. Nice work, Garth -- yours are even nestable! Also the web page is well written, and you're offering macro files to download... Plainly a lot of work invested there. (Ditto for the 65816 macros on BDD's site.)
there will be countless other needs for branches where it would be nice to avoid adding a label .... I had tons of labels like aafd1 or mcp2
Aside from having to create the name, another reason I dislike these nuisance labels is that someone reading the code and seeing the label might wonder, "
what else jumps there?". The structured conditionals give a better picture of what's going on.
-- Jeff
Re: Kowalski Simulator
Posted: Thu Sep 13, 2012 6:02 pm
by GARTHWILSON
another reason I dislike these nuisance labels is that someone reading the code and seeing the label might wonder, "what else jumps there?".
Yes, and when I've made a change in the code here and there and eliminated a branch, I had to do a search to see if I can eliminate the label without breaking something else.
Thanks for the compliments on the article.
Edit: I added more structure macros and some accessory macros to it in May 2013, most importantly the FOR_X...NEXT_X and FOR_Y...NEXT_Y with lots of options for how to use them, improving the loops where you would use X or Y as counters. They're nestable too.
Re: Kowalski Simulator
Posted: Sat May 25, 2013 6:30 pm
by Dr Jefyll
something's not right in [the lead post, excerpted below]. The two's complement of 1 is $FF, not $FE.
I'll have to check it out. I went by what the assembler generated and didn't think to manually code and run it on POC to check the result.
Hi BDD - just a reminder this error stands uncorrected. And I don't understand your response. Do you mean the assembler resolved the expression ~1 as equaling $FE, and, from that, you concluded that the tilde signified
two's complement? $FE is the
one's complement -- surely that's rudimentary. Can you explain the advantage of coding an example?
cheers,
Jeff
- ~ - Twos complement
Usage: ~<expr>; ~ is a unary operator
Effect: Computes twos complement of <expr>
Example: STEP = ~$01
Result: STEP = $FE
Re: Kowalski Simulator
Posted: Sun May 26, 2013 5:50 am
by BigDumbDinosaur
something's not right in [the lead post, excerpted below]. The two's complement of 1 is $FF, not $FE.
I'll have to check it out. I went by what the assembler generated and didn't think to manually code and run it on POC to check the result.
Hi BDD - just a reminder this error stands uncorrected. And I don't understand your response. Do you mean the assembler resolved the expression ~1 as equaling $FE, and, from that, you concluded that the tilde signified
two's complement? $FE is the
one's complement -- surely that's rudimentary. Can you explain the advantage of coding an example?
cheers,
Jeff
- ~ - Twos complement
Usage: ~<expr>; ~ is a unary operator
Effect: Computes twos complement of <expr>
Example: STEP = ~$01
Result: STEP = $FE
Actually, I had the info to fix this and forgot all about it. The original post has been corrected.