|
PowerBASIC Forums
![]() PowerBASIC for Windows
![]() Use MASM code in PB
|
| next newest topic | next oldest topic |
| Author | Topic: Use MASM code in PB |
|
Steve Hutchesson Member |
I have on and off needed to use some code from MASM in PB and while simple mnemonic code translates to PB inline easily enough, due to the differences between a compiler and an assembler, some forms don't translate properly. I have just tested out an idea that makes it a lot easier to port some forms of MASM procedures to PB and it is because PB properly supports the "db" format for BYTE data. It take 2 programs, one in MASM to extract the MASM procedure and Below is the code for both. The test procedure is trivial with a MOV
The PB test file.
Regards, hutch at movsd dot com ------------------ IP: Logged |
|
Steve Hutchesson Member |
Here is another version created the same way from two algorithms in MASM to create and read a character tree that has some of the characteristics of a binary tree.
Regards, hutch at movsd dot com ------------------ IP: Logged |
|
Paul Breen Member |
I can't find any background info on the "db" format. I have searched the data types in the manual. Is this documented for PowerBasic? This table of some kind seems to be the key to a lot of fast routines that Hutch posts here. I need a slower expanation of the "table" part of the code to understand how it works. ------------------ IP: Logged |
|
Eddy Van Esch Member |
Paul, The 'db' keyword is just a way to create a table in ASM. It is basically a handy way to insert numbers (data) in your PB/ASM program.
'! call addit' jumps to the start of the code, indicated with label 'addit'. Clear as mud? Kind regards ------------------ IP: Logged |
|
SG Dunn Member |
[deleted as duplicate] [This message has been edited by SG Dunn (edited April 13, 2006).] IP: Logged |
|
Eddy Van Esch Member |
Maybe I forgot to mention this important thing. The assembler code as in :
are not generated 'by hand'. They are the output of an assembler like MASM. What Steve showed here is a way to assemble code using an assembler like MASM for example, and directly use that code in PB by inserting the opcodes as !db statements .. Kind regards
[This message has been edited by Eddy Van Esch (edited April 13, 2006).] IP: Logged |
|
Paul Breen Member |
Thanks, every little bit helps. It is the structure of the table that perplexes me. In the addit: ! db 85,139,236,139,69,8,3,69,12,201,194,8,0 there are only 13 bytes. This will leave some bits "undefined"?. Is 1 and 2 below the same? 1) asm db 1,2,3 the same as: 2) asm db 1 asm db 2 asm db 3 ------------------ IP: Logged |
|
Steve Hutchesson Member |
Paul, I probably should have made more sense of this posting in the first What I was trying to get around is PB does not support external object I did it in MASM by putting a label before and after a complete procedure The rest is just using PUSH / CALL assembler notation to call the It works fine but it has serious limitations in what can be done with it. Regards, hutch at movsd dot com ------------------ IP: Logged |
|
Eddy Van Esch Member |
quote: ---I'm not sure I follow you here, Paul. What exactly do you mean by 'bits undefined' ? This particular db statement simply inserts these 13 bytes in your code. The first one being located at address 'addit'. By jumping to address addit ('! call addit') this code is executed.
quote: ---- Yes, they both insert 3 bytes (bytes 1, 2 and 3) in your code. Kind regards ------------------ [This message has been edited by Eddy Van Esch (edited April 15, 2006).] IP: Logged |
|
David Gwillim Member |
Now wouldn't it be nice if PB's built-in assembler could handle the MASM style db for string creation: db "This is a string that I will terminate with a zero byte",0 Dave ------------------ GAIA - the Mother of us all IP: Logged |
|
Steve Hutchesson Member |
David, 2 things, with masm, you need to name the data item so you can reference it.
The other is the CHR$() notation in PB will do this for you.
This is a good capacity in PB that seems to be underused or not Regards, hutch at movsd dot com ------------------ IP: Logged |
|
David Gwillim Member |
Hi Hutch, Sorry for confusing the issue by leaving off the identifier/label This compiles in PB: This doesn't: Thanks for the inpriration of using chr$() for putting what is effectively a long text constant In your use of chr$(), I think you meant: $textitem = chr$("Hi, I am an ascii text example",0) or Sub MySub() textitem$ = chr$("Hi, I am an ascii text example",0) The only problem with chr$() used like this is that the limit that can textitem$ = $help01 + $help02 + $help03 ... $helpNN will fail once the concatenation exceeds 255 bytes. Using asm db there is only the limit of the size of a function/sub whatever Up until now the only way that I knew of in PB to do large "constant" strings is to build them HelpText$ = $help01 There's no limit to what a string VARIABLE can contain except that set by the OLE engine. But I just tried chr$() in this role and it works just great! You can do the equivalent of creating a large
The above compiles just fine and gives string length report of 721 characters. Thanks for the inspiration Hutch. Dave ------------------ GAIA - the Mother of us all [This message has been edited by David Gwillim (edited April 16, 2006).] IP: Logged |
|
Paul Breen Member |
I did a little experimenting with pbcc,winhex and pe explorer. asm db 65 asm db 66 asm db 67 asm db 67,66,65 waitkey$ This compiles and it answers my own question. You can read Hutch, what if you put a "marker" or header sequence in memory. Eddy, about the "undefined bits, before I actually used the hex ------------------ IP: Logged |
|
Steve Hutchesson Member |
Paul, An assembler is a different animal to a compiler and you can routinely Something like this.
In the .DATA section you write a DWORD variable like this.
The variable "proclen" is the number of bytes contained between the two labels. At runtime, you load the 1st label then write the number of bytes The rest is a conversion to PB notation and call the code using Regards, hutch at movsd dot com ------------------ IP: Logged |
|
Eddy Van Esch Member |
quote: You can also do this in PB like shown below. Although it would not make much sense to extract code from a PB program and to insert it as databytes into another PB program .. Of course, you have to be careful what you put inside the routine.
Kind regards
[This message has been edited by Eddy Van Esch (edited April 16, 2006).] IP: Logged |
All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright й 1999-2007 PowerBASIC, Inc. All Rights Reserved.