I'm not sure exactly what you are trying to do... You have an assembly routine already written, and you're trying to include it into your QBASIC program? This is relatively easy. You have it in your program already, and you're trying to debug it by shelling to Debug? This is trickier.
In Windows, you can copy and paste from and to DOS windows. In 98 this is easy; you should have a toolbar with buttons on your console window. In XP, you can right click the title bar of your DOS menu. Also, you can redirect input when you run debug, but only do this if you know what you are doing.
I recommend using the FreeDOS version of Debug. It supports 32 bit instructions.
Do you have Nasm yet? It is a free (LGPL) assembler, and it is very useful.
>line label support
Please clarify. Do you mean symbols in Nasm source?
You might take a look through this thread:
http://www.network54.com/Forum/171757/m ... 067704622/
Once you have the binary assembled code (either from Debug or Nasm), you can include it in your QBASIC program in several ways...
Take as an example one of the hello world examples in that thread I just referred to. The Nasm source is:
Code: Select all
;assemble in nasm
org 0x0 ;origin for nasm
;we need an absolute near address for the display string function, but we don't know where QBASIC has placed this code.
call _next
_next:
;this will be encoded with a relative offset (0x0), so will work. It places the return address on the stack. The return address in this case is the same as the destination address, the address of the _next label.
pop bx
;now we recover that address from the stack. We now know the absolute near address of the _next label.
sub bx,byte _next
;this gives us the absolute near address of the beginning of the code in QBASIC's memory. We will calculate the absolute addresses of other labels by adding this value from the addresses generated by nasm, which are based on an origin of 0x0.
mov dx,_text
add dx,bx ;explained above
mov ah,0x9
int 0x21
retf
_text:
db "Hello, world!",0xd,0xa,"$"
You can generate the same file by typing/pasting exactly this into FreeDOS Debug (must be modified for MS-DOS Debug):
Code: Select all
n hello.bin
r cx 21
a 100
call 103
pop bx
sub bx,3
mov dx,11
add dx,bx
mov ah,9
int 21
retf
db "Hello, world!",d,a,"$"
w
q
either way, you should create a binary file with this content in hex:
E8 00 00 5B 83 EB 03 BA 11 00 01 DA B4 09 CD 21 CB 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24
Now, you can use those hex values in your QBASIC program like this, or some other way:
Code: Select all
DEFINT A-Z
CONST l = 33
DIM c AS STRING * l
DIM t AS STRING
DIM i AS INTEGER
t = "E800005B83EB03BA110001DAB409CD21CB48656C6C6F2C20776F726C64210D0A24"
IF LEN(t) <> (l * 2) THEN SYSTEM 'just an unneccessary safeguard
FOR i = 0 TO l - 1
MID$(c, i + 1, 1) = CHR$(VAL("&h" + MID$(t, i * 2 + 1, 2)))
NEXT i
CLS
DEF SEG = VARSEG(c)
CALL absolute(VARPTR(c))
To view the code in Debug after it has been loaded by QBASIC, you can do something like this:
PRINT HEX$(VARSEG(c)); ":"; HEX$(VARPTR(c))
SHELL "debug" 'FreeDOS debug
Then type:
r cs whateversegment
u whateveroffset
example screen:
Code: Select all
4511:7EDE
-r cs 4511
-u 7ede
4511:7EDE E80000 CALL 7EE1
4511:7EE1 5B POP BX
4511:7EE2 83EB03 SUB BX,+03
4511:7EE5 BA1100 MOV DX,0011
4511:7EE8 01DA ADD DX,BX
4511:7EEA B409 MOV AH,09
4511:7EEC CD21 INT 21
4511:7EEE CB RETF
4511:7EEF 48 DEC AX
4511:7EF0 65 SEG GS (unused)
4511:7EF1 6C INSB
4511:7EF2 6C INSB
4511:7EF3 6F OUTSW
4511:7EF4 2C20 SUB AL,20
4511:7EF6 776F JA 7F67
4511:7EF8 726C JB 7F66
4511:7EFA 64210D AND FS:[DI],CX
4511:7EFD 0A24 OR AH,[SI]
-
If you set the registers correctly, you could procede through the code,
but be careful not to execute the retf.
If you still have trouble, please post your code, both QBASIC and assembly.
Regards,
Michael