6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri May 10, 2024 5:13 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Kowalski Simulator
PostPosted: Fri Sep 16, 2011 8:00 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8178
Location: Midwestern USA
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:
   .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

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Last edited by BigDumbDinosaur on Sun May 26, 2013 7:12 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Sat Sep 17, 2011 7:19 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 993
Location: near Heidelberg, Germany
BigDumbDinosaur wrote:
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é


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Wed Sep 12, 2012 2:59 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
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:
     ...
     ...
     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.)

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Wed Sep 12, 2012 6:37 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8178
Location: Midwestern USA
Dr Jefyll wrote:
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:
         ...
         ...
         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:
         ...
         ...
         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.

Quote:
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.:

Code:
isrmask  =@00111001

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.

Quote:
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.

Quote:
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.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 12:26 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
Quote:
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:
         ...
         ...
         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:
         ...
         ...
         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.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 1:14 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8178
Location: Midwestern USA
Dr Jefyll wrote:
Code:
         ...
         ...
         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.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 3:51 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Why not structure macros. No label needed.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 4:27 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8178
Location: Midwestern USA
GARTHWILSON wrote:
Why not structure macros. No label needed.

:D I figured you would suggest that! :D

Code:
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.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 5:06 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
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.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 1:48 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
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.)

GARTHWILSON wrote:
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

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Thu Sep 13, 2012 6:02 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Quote:
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.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Sat May 25, 2013 6:30 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
I wrote:
something's not right in [the lead post, excerpted below]. The two's complement of 1 is $FF, not $FE.
BigDumbDinosaur wrote:
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
BigDumbDinosaur wrote:
  • ~ - Twos complement
    Usage: ~<expr>; ~ is a unary operator
    Effect: Computes twos complement of <expr>
    Example: STEP = ~$01
    Result: STEP = $FE

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Kowalski Simulator
PostPosted: Sun May 26, 2013 5:50 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8178
Location: Midwestern USA
Dr Jefyll wrote:
I wrote:
something's not right in [the lead post, excerpted below]. The two's complement of 1 is $FF, not $FE.
BigDumbDinosaur wrote:
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
BigDumbDinosaur wrote:
  • ~ - 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.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: