AIM, OIM vs BCLR, BSET
-
- Posts: 32
- Joined: Tue Apr 04, 2023 9:11 am
AIM, OIM vs BCLR, BSET
Hey folks,
I've been using asm6303 under dos and it works fine for me, but i thought i'd give org2asm.tcl a go.
org2asm doesn't appear to support BCLR & BSET, i know i should us AIM & OIM but can never get it to do what i want
here's a snippet
300E 71 BF 17 BCLR 6,POB_PORT6 ; SET CS3 LOW
3011 72 08 17 BSET 3,POB_PORT6 ; SET SOE_B HIGH
now this is fine for asm6303 but not org2asm, what would be the AIM workaround?
kinda struggling here, AIM $40,POB_PORT6 doesn't work
Thanks Shaun
I've been using asm6303 under dos and it works fine for me, but i thought i'd give org2asm.tcl a go.
org2asm doesn't appear to support BCLR & BSET, i know i should us AIM & OIM but can never get it to do what i want
here's a snippet
300E 71 BF 17 BCLR 6,POB_PORT6 ; SET CS3 LOW
3011 72 08 17 BSET 3,POB_PORT6 ; SET SOE_B HIGH
now this is fine for asm6303 but not org2asm, what would be the AIM workaround?
kinda struggling here, AIM $40,POB_PORT6 doesn't work
Thanks Shaun
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
Hi,
The bit set and clear type instructions are not part of the instruction set, so have to be implemented as macros. This file:
https://github.com/blackjetrock/psion-o ... OSHEAD.INC
has some bit set/clr macros at the start which should do what you are after.
The syntax that I used for org2asm is the one that is used by the Psion macro assembler, so that DICT.SRC file has examples of instruction syntax. There is a difference, though in that org2asm
uses
ADDA
rather than
ADD A
for example. I coded to the 6303 datasheet and it made some code a bit simpler.
Sorry for the lack of documentation. The assembler was put together so I could have a native Linux assembler to assemble some top slot ROM test code.
I'm away from my laptop at the moment so can't assemble anything. I'll have a look at the AIM instruction you listed, and see if I can see the problem when I get back. I don't think the assembler has any built-in definitions for port6 etc, they have to come from included files. The Psion .INC files should all work, macros and all.
Andrew
The bit set and clear type instructions are not part of the instruction set, so have to be implemented as macros. This file:
https://github.com/blackjetrock/psion-o ... OSHEAD.INC
has some bit set/clr macros at the start which should do what you are after.
The syntax that I used for org2asm is the one that is used by the Psion macro assembler, so that DICT.SRC file has examples of instruction syntax. There is a difference, though in that org2asm
uses
ADDA
rather than
ADD A
for example. I coded to the 6303 datasheet and it made some code a bit simpler.
Sorry for the lack of documentation. The assembler was put together so I could have a native Linux assembler to assemble some top slot ROM test code.
I'm away from my laptop at the moment so can't assemble anything. I'll have a look at the AIM instruction you listed, and see if I can see the problem when I get back. I don't think the assembler has any built-in definitions for port6 etc, they have to come from included files. The Psion .INC files should all work, macros and all.
Andrew
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
OK, after a bit of fiddling I have found the following:
The LZ include files in the testpak directory of the repository seem to have different macro syntax to what I assume is the XP include files. So, in OSHEAD.INC (the file linked above) the macro syntax isn't the same as the one I used modelled on MOSHEAD.INC.
Anyway, I have created a file aim_test.asm which has the following:
When assembled with org2asm.tcl, the .lst file gives this:
This is the same object code as the example given above from asm6303. I've had to change the syntax of the macro to match the syntax I used, and anyone who is still reading may have noticed that I have had to use a mask value as one of the arguments to the BSET and BCLR macros. This is different to the asm6303 instructions.
That's not a problem, though, as we have the source code to the org2asm.tcl assembler, as it's a Tcl script. We can create a new operator, I will use ^B to convert a bit number to a mask. That can then be used in the macro expansion to get a mask from a bit number like the asm6303 assembler does.
Adding that to the Tcl and using this:
which has bit numbers for the bit set and clear macros. The macros BCLR and BSET have been altered to use the new ^B operator. It's modelled on the ^A operator of the Psion assembler. The syntax is:
^Bdnd
where d is a delimiter (any character) and n is the bit number.
So ^B=6= represents the bit mask where bit 6 is set, or 0x40.
The output from the modified org2asm.tcl is this:
That now generates the same output as asm6303 from the same source.
I've pushed the updated org2asm.tcl and the aim_test.asm file to the repository.
Andrew
The LZ include files in the testpak directory of the repository seem to have different macro syntax to what I assume is the XP include files. So, in OSHEAD.INC (the file linked above) the macro syntax isn't the same as the one I used modelled on MOSHEAD.INC.
Anyway, I have created a file aim_test.asm which has the following:
Code: Select all
.INCLUDE MOSVARS.INC
.INCLUDE MOSHEAD.INC
.INCLUDE MSWI.INC
;/** Macro definitions from OSHEAD.INC ****/
;/****************** MACRO DEFINITIONS ******************************/
BSET .macro mask, addr
oim #mask, addr
.endm
BCLR .macro mask, addr
aim #^Cmask, addr
.endm
BTGL .macro mask, addr
eim #mask, addr
.endm
BTST .macro mask, addr
tim #mask, addr
.endm
.org $1000
AIM #^x40, POB_PORT6
os POB_PORT6
.org $300e
BCLR $40,POB_PORT6
BSET $08,POB_PORT6
Code: Select all
0000 0000 1000 1000 0000 (O) .org $1000
0000 0000 1000 1000 0000 (6) 71 40 17 AIM #^x40, POB_PORT6
0003 0003 1003 1003 0000 (B) 3F .byte ^X3F,POB_PORT6
0004 0004 1004 1004 0000 (B) 17 .byte ^X3F,POB_PORT6
0005 0005 300E 300E 0000 (O) .org $300e
0005 0005 300E 300E 0000 (6) 71 BF 17 aim #^C$40, POB_PORT6
0008 0008 3011 3011 0000 (6) 72 08 17 oim #$08, POB_PORT6
That's not a problem, though, as we have the source code to the org2asm.tcl assembler, as it's a Tcl script. We can create a new operator, I will use ^B to convert a bit number to a mask. That can then be used in the macro expansion to get a mask from a bit number like the asm6303 assembler does.
Adding that to the Tcl and using this:
Code: Select all
.INCLUDE MOSVARS.INC
.INCLUDE MOSHEAD.INC
.INCLUDE MSWI.INC
;/** Macro definitions from OSHEAD.INC ****/
;/****************** MACRO DEFINITIONS ******************************/
BSET .macro mask, addr
oim #^B=mask=, addr
.endm
BCLR .macro mask, addr
aim #^C^B=mask=, addr
.endm
BTGL .macro mask, addr
eim #mask, addr
.endm
BTST .macro mask, addr
tim #mask, addr
.endm
.org $1000
AIM #^x40, POB_PORT6
os POB_PORT6
.org $300e
BCLR 6,POB_PORT6
BSET 3,POB_PORT6
^Bdnd
where d is a delimiter (any character) and n is the bit number.
So ^B=6= represents the bit mask where bit 6 is set, or 0x40.
The output from the modified org2asm.tcl is this:
Code: Select all
0000 0000 1000 1000 0000 (O) .org $1000
0000 0000 1000 1000 0000 (6) 71 40 17 AIM #^x40, POB_PORT6
0003 0003 1003 1003 0000 (B) 3F .byte ^X3F,POB_PORT6
0004 0004 1004 1004 0000 (B) 17 .byte ^X3F,POB_PORT6
0005 0005 300E 300E 0000 (O) .org $300e
0005 0005 300E 300E 0000 (6) 71 BF 17 aim #^C^B=6=, POB_PORT6
0008 0008 3011 3011 0000 (6) 72 08 17 oim #^B=3=, POB_PORT6
I've pushed the updated org2asm.tcl and the aim_test.asm file to the repository.
Andrew
-
- Posts: 32
- Joined: Tue Apr 04, 2023 9:11 am
Re: AIM, OIM vs BCLR, BSET
Thanks so much Andrew, just getting my head around org2asm, ill have to read your reply numerous times to understand it, but ill test it out now and see if i understand, thanks again for the explanation
All the best
Shaun
All the best
Shaun
-
- Posts: 32
- Joined: Tue Apr 04, 2023 9:11 am
Re: AIM, OIM vs BCLR, BSET
Thanks for awesome support, my Dr says my 53yo brain has developed bad sectors so i really appreciate the help given on this forum,
so yes, my ASM6303 code now works in org2asm, many thanks Andrew,
ASM6303 code
vs org2asm code, the final hex output is the same
All the best Shaun
so yes, my ASM6303 code now works in org2asm, many thanks Andrew,
ASM6303 code
Code: Select all
0001 START:
0000 4F CLRA
0001 5F CLRB
+
0002 C6 03 LDAB #PAKD
0004 3F 62 OS PK$SETP ; SELECT TOP SLOT
+
0006 C6 03 LDAB #03h ; 00000011b
0008 D7 01 STAB POB_DDR2 ; PORT 2 ALL OUTPUT
+
000A 71 BF 17 BCLR 6,POB_PORT6 ; SET CS3 LOW
000D 72 08 17 BSET 3,POB_PORT6 ; SET SOE_B HIGH
0001 INIT:
0010 86 00 LDAA #00h ; INITIAL VALUE
0012 36 PSHA
0001 LOOP:
0013 32 PULA ; GET A
0014 97 03 STAA POB_PORT2 ; SEND TO PORT 2
0016 4C INCA ; A+=1
0017 36 PSHA ; SAVE A
+
0018 CE 5A A0 LDX #5AA0h ;FOR DELAY OF 100MS
001B 09 DLOOP: DEX
001C 26 FD BNE DLOOP
+
001E 3F 46 OS KB$BREK ; ON/CLR PRESSED?
0020 24 F1 BCC LOOP ; IF NOT
0022 32 PULA ; RELEASE A OFF STACK
0023 20 00 BRA EXIT ; IF PRESSED
+
0001 EXIT:
0025 71 F7 17 BCLR 3,POB_PORT6 ; SET SOE_B LOW
0028 72 40 17 BSET 6,POB_PORT6 ; SET CS3 HIGH
002B 39 RTS
Code: Select all
0000 0000 0000 0000 0000 (L) START:
0000 0000 0000 0000 0000 (5) 4F CLRA
0001 0001 0001 0001 0000 (5) 5F CLRB
0002 0002 0002 0002 0000 (1) C6 03 LDAB #PAKD
0004 0004 0004 0004 0000 (B) 3F .byte ^X3F,pk$setp
0005 0005 0005 0005 0000 (B) 62 .byte ^X3F,pk$setp
0006 0006 0006 0006 0000 (1) C6 03 LDAB #03 ; 00000011b
0008 0008 0008 0008 0000 (2) D7 01 STAB POB_DDR2 ; PORT 2 ALL OUTPUT
000A 000A 000A 000A 0000 (6) 71 BF 17 aim #^C^B=6=, POB_PORT6
000D 000D 000D 000D 0000 (6) 72 08 17 oim #^B=3=, POB_PORT6
0010 0010 0010 0010 0000 (L) INIT:
0010 0010 0010 0010 0000 (1) 86 00 LDAA #0 ; INITIAL VALUE
0012 0012 0012 0012 0000 (5) 36 PSHA
0013 0013 0013 0013 0000 (L) LOOP:
0013 0013 0013 0013 0000 (5) 32 PULA ; GET A
0014 0014 0014 0014 0000 (2) 97 03 STAA POB_PORT2 ; SEND TO PORT 2
0016 0016 0016 0016 0000 (5) 4C INCA ; A+=1
0017 0017 0017 0017 0000 (5) 36 PSHA ; SAVE A
0018 0018 0018 0018 0000 (1) CE 5A A0 LDX #$5AA0 ;FOR DELAY OF 100MS
001B 001B 001B 001B 0000 (5) 09 DLOOP: DEX
001C 001C 001C 001C 0000 (0) 26 FD BNE DLOOP
001E 001E 001E 001E 0000 (B) 3F .byte ^X3F,kb$brek
001F 001F 001F 001F 0000 (B) 46 .byte ^X3F,kb$brek
0020 0020 0020 0020 0000 (0) 24 F1 BCC LOOP ; IF NOT
0022 0022 0022 0022 0000 (5) 32 PULA ; RELEASE A OFF STACK
0023 0023 0023 0023 0000 (0) 20 00 BRA EXIT ; IF PRESSED
0025 0025 0025 0025 0000 (L) EXIT:
0025 0025 0025 0025 0000 (6) 71 F7 17 aim #^C^B=3=, POB_PORT6
0028 0028 0028 0028 0000 (6) 72 40 17 oim #^B=6=, POB_PORT6
002B 002B 002B 002B 0000 (5) 39 RTS
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
No problem, I'm just glad someone else is using it. I probably need to put the posts here into the repository somehow.
org2asm.tcl is a 5 pass assembler because when you assemble 6303 code you have zero page accesses which are shorter than the extended addressing mode. Sometimes you can use a 2 byte instruction to address memory instead of a 3 byte instruction. On the first pass a 3 byte instruction may be used for a reference, but as a 2 byte instruction is used elsewhere that may mean that a 2 byte instruction could be used in place of the 3 byte instruction. On the next pass the assembler uses a 2 byte instruction and gets slightly shorter code. That then means some other instructions could be 2 byte and so on. I found that 5 passes seemed to be enough to get optimal code. If you are comparing the output code to another assembler, you may find that the object code is slightly different because of different optimisation in this way. For instance, the DICT example code that I used as a test for the assembler is one or two bytes shorter with org2asm than the Psion assembler because of these 2byte/3 byte instruction differences.
Just something to watch out for.
Andrew
org2asm.tcl is a 5 pass assembler because when you assemble 6303 code you have zero page accesses which are shorter than the extended addressing mode. Sometimes you can use a 2 byte instruction to address memory instead of a 3 byte instruction. On the first pass a 3 byte instruction may be used for a reference, but as a 2 byte instruction is used elsewhere that may mean that a 2 byte instruction could be used in place of the 3 byte instruction. On the next pass the assembler uses a 2 byte instruction and gets slightly shorter code. That then means some other instructions could be 2 byte and so on. I found that 5 passes seemed to be enough to get optimal code. If you are comparing the output code to another assembler, you may find that the object code is slightly different because of different optimisation in this way. For instance, the DICT example code that I used as a test for the assembler is one or two bytes shorter with org2asm than the Psion assembler because of these 2byte/3 byte instruction differences.
Just something to watch out for.
Andrew
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
While I am in the area of the assembler I have expanded the information in the README, added a syntax_test.asm file that has examples of syntax and added a shorter .lst file output that doesn't have all the detailed clutter of the full .lst file.
Andrew
Andrew
- Martin
- Global Admin
- Posts: 225
- Joined: Mon Jan 02, 2023 5:18 pm
Re: AIM, OIM vs BCLR, BSET
Hi Andrew
phpBB Forum Software doesn't have a file repository as such.. You can of course add files to posts but I understand the issue of them getting buried as new posts are added. I could create a Forum thread called 'Repository' and members could post links to their posts with the file attachments so other members could look there. Of could this is not ideal as it adds another layer (hoop) that the member must go though to have their 'uploads' listed. If it was a large forum with many members then it would be unmanageable but as there are only a few of us it might be possible.
I'd be interest to see what members think before going ahead. Remember every time you attached something you want in the repository you will have to create another post in there that links to the original.
Sincerely and in good faith
Martin
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
Ah, the repository I meant was the github repository. Multiple locations for things is always a good idea, though.Martin wrote: ↑Sat Aug 26, 2023 9:14 amHi Andrew
phpBB Forum Software doesn't have a file repository as such.. You can of course add files to posts but I understand the issue of them getting buried as new posts are added. I could create a Forum thread called 'Repository' and members could post links to their posts with the file attachments so other members could look there. Of could this is not ideal as it adds another layer (hoop) that the member must go though to have their 'uploads' listed. If it was a large forum with many members then it would be unmanageable but as there are only a few of us it might be possible.
I'd be interest to see what members think before going ahead. Remember every time you attached something you want in the repository you will have to create another post in there that links to the original.
Sincerely and in good faith
Martin
It does seem quite involved to do it on the forum from your description.
Andrew
-
- Posts: 204
- Joined: Tue Jan 03, 2023 7:54 pm
Re: AIM, OIM vs BCLR, BSET
I've tweaked org2asm a bit and have updated the README in the repository.
Andrew
Andrew