Vic's QBasic Programming Tutorial Basic Tutorial XIII USING BASIC ASM IN YOUR BASIC PROGRAM!!! This actually is more complicated then ASM itself!!! ----------------------------------------------------------------------------- Before I start On this tutorial, I want to admit something... This tutorial was done before By a genius called Aaron Severn back in 1997... That tutorial has everything you could want, but I think that it leaves some things out... It also leeves out some details. At the time I learned this, I did not know that that tutorial existed, (I wish I did!!), I picked it up from some peoples source code, so I don't consider this plagerism... --- Ok, where to start... First, why use ASM at all... 1. Its fast... 2. It can do many many things that Qbasic can't do on its own... 3. well, I guess #2 covers everything doesn't it?? --- Ok, What must you do first? !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!NOTE: This tutorial expects that you read the last one on ASM... !! !! This tutorial does not teach asm... !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Ok, lets start of by using the mouse ASM program we used in the last tutorial... remember? mov ax,1 int 33 RETF Ok, you might not remember the RETF, but we need it to shut down the program withought crashing... just remember to put it at the end of your program... now what? well, Qbasic would not understand this program in this format, so, we have to make it more Qbasic friendly... How? (I ask more questions than you probly do!) by converting it from ASM to MACHINE Code... ------------------- CONVERTING ASM TO MACHINE CODE: There are a few ways to convert ASM to Machine code... the ways that I use are... 1. Memorizing 2. Using Debug's Desembler or Unasembler or whatever its called... #1. Memorizing... 'If your no interested in the word memorizing skip this The MOV command would be the machine code equivalent of "B8" so, the first command "mov ax,1" would look like this in Machine code "B80100" The INT command would be the machine code equivalent of "CD" so, the second command "int 33" would look like this... "CD33" Finally, the RETF command (which is equal to "CB" would look like this "CB" So, all together, the program would look like this... B80100 CD33 CB You would have to memorize each command... I don't recomend this!!! This is the way I originally did it until I found Aaron Severn's tutor... ------------- #2. Using Debug!! (easy... LISTEN!!!!!) ok, this is going to sound a little familiar... I hope! goto a dos prompt (command.com) and type DEBUG type a to go to assembler mode Now, type in the program ps. don't write the {enter}s mov ax,1 {enter} int 33 {enter} RETF {enter} {enter} that should bring you back to the - prompt (if not, hit enter again) Now, type u and you should see this on your screen... ---------- 197A:0100 B80100 MOV AX,0001 197A:0103 CD33 INT 33 197A:0105 CB RETF 197A:0106 A7 CMPSW 197A:0107 D802 FADD DWORD PTR [BP+SI] 197A:0109 3C2A CMP AL,2A 197A:010B 7505 JNZ 0112 197A:010D 800EA7D802 OR BYTE PTR [D8A7],02 197A:0112 3A0694D2 CMP AL,[D294] 197A:0116 75C9 JNZ 00E1 197A:0118 4E DEC SI 197A:0119 32C0 XOR AL,AL 197A:011B 8634 XCHG DH,[SI] 197A:011D 006919 ADD [BX+DI+19],CH --------------- 'or something like this... !!!! whats all that crap for??? well, My best guess, would be that thats left over from another program... The only part that you need to pay attention to is the stuff that contains your program code... EX. 197A:0100 B80100 MOV AX,0001 197A:0103 CD33 INT 33 197A:0105 CB RETF Look over to the right of that ^ ^ Thats our complete program... look over to the left... past the 197A:0100... you see B80100... That is those commands (to the right...) in machine code... It did it for you!!! GREAT!!! Do you get it??? -------------- Using MACHINE CODE in QBasic... --- Each two digit number (in HEX.. (i'll explain later!)) is a command, or a number... So, qbasic needs the program seperated into 2 digit #'s... so the above program... B80100 CD33 CB needs to look like this... B8 01 00 CD 33 CB but, even now After it is machine code and seperated, QB will not understand it... you have to tell QB that they are HEX and not Decimal numbers and then put it all into an array... Then your finished... Here we go!! --- How to tell QB the numbers Are HEX... Since this is a basic ASM in QB tutor I will cover the easy most understandable explaination... In a more advanced tutorial, I plan to cover a different way... for now just use this... Lets take the first 2 digit HEX command B8... in order for qb to understand it as hex we need to present it like this... CHR$(&HB8) Lets disect this... CHR$( &H B8 ) ^ ^ ^ ^ changes to Makes it The command Closing character. HEX... ... ... Ok... Lets look at the next one 01... CHR$(&H01) Disect again... CHR$( &H 01 ) ^ ^ ^ ^ changes to Makes it The command Closing character. HEX... ... ... do you get it yet? I hope so... ------ Putting the hex into an array... This is simple... do you remember how to add words together in qb? like this ' First QB example in a long time (copy into QB...) ONE$ = "School " TWO$ = "Sucks!" THREE$ = ONE$ + TWO$ Print THREE$ END '---- end example... In this example, the words are connected... How do we do this with HEX? The same way! The mouse program would look like this... this is the original (not ready for QB) B8 01 00 CD 33 CB This is what it would look like going into an array... ASM$ = ASM$ + CHR$(&HB8) + CHR$(&H01) + CHR$(&H00) ASM$ = ASM$ + CHR$(&HCD) + CHR$(&H33) ASM$ = ASM$ + CHR$(&HCB) can you see how its done??? ----- OK Qbasic Can see the ASM program... Now what?? All we have to do now, is tell QB to execute the above code as an ASM file... So, the program is stored as one array called ASM$... That is what we have to tell QB to Run... What command do we use to run it? I am sure you have seen this before... It is called CALL ABSOLUTE... !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !NOTE: if you are using QB 4.0 or above, you have to start qbasic in a dos ! ! Box (command.com) whith the line c:\qbdir\qb /l If you don't ! ! then QB will not recognize the Call absolute command... ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! This is how you would call the call absolute... Memorize this... DEF SEG = VARSEG(ASM$) CALL ABSOLUTE (SADD(ASM$)) Thats IT!! Your finished!!! Here is the total program... (copy and paste this into a qbasic dos window) '---------- QB ASM MOUSE EXAMPLE SCREEN 13 ASM$ = ASM$ + CHR$(&HB8) + CHR$(&H01) + CHR$(&H00) ASM$ = ASM$ + CHR$(&HCD) + CHR$(&H33) ASM$ = ASM$ + CHR$(&HCB) DEF SEG = VARSEG(ASM$) CALL ABSOLUTE (SADD(ASM$)) '------- END EXAMPLE Wow, that was a lot of explaining to do for such a short example... This method is to do something that does not require input or output into and out from QBASIC... In the next ASM tutorial I will show you how to interact with the ASM that is running. Examples of this is how to get the mouse position into qbasic, and how to set the mouse position... This gets really ASM advanced... If you want to know when this or any other tutorial is out make sure to sign up on the list (look at the bottom of this file...) ----------------------------------------------------------------------------- Thats it for this tutorial, If I didn't get into enough detail in the explanations then just look at the source code and try to figure it out on your own. All else fails E-Mail Me... I want to make these tutorials as easy to understand as posible!!! My current E-Mail address is RADIOHANDS@AOL.com If you are using this tutorial on your page, please leave the tutorial exactly as it is... please don't change anything, unless its spelling errors... Theres alot of them! I don't like using the backspace key... The original website that these were on is http://members.aol.com/radiohands/index.html Thank you Vic Luce Finished January 21 2000 If you want to be notified when a new tutorial is out.. Send An E-mail to RADIOHANDS@AOL.com with the subject saying VQBLIST and then your E-mail address(check website)