Author Topic: Mixing nasm and quick basic  (Read 16064 times)

nobody

  • Guest
Mixing nasm and quick basic
« on: October 19, 2009, 01:49:18 PM »
Hello. What i want to do is execute in nasm a quick basic procedure, in this case B$PESD which print a string via its descriptor. I have done it already in masm, but nasm is a little difficult ¿maybe "extern" fails, because it must be far?

SEGMENT Datos
msg         DB 'Hola, Quick Basic!'
Descriptor  DW 18, msg
SEGMENT Pila STACK
RESB 256
InicioPila:

EXTERN  B$PESD           ; Esto lo recogemos de BCOM45.LIB
SEGMENT Codigo FAR
..start:
MOV      AX, Pila
MOV      SS, AX
MOV      SP, InicioPila
MOV      AX, Datos
MOV      DS, AX
MOV      AX, Descriptor
PUSH     AX
CALL     FAR B$PESD
MOV      AH, 4ch
INT      21h

; To compile it:
; nasmw -f obj AsmNQB.asm
; link AsmNQB,,,BCOM45;

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Mixing nasm and quick basic
« Reply #1 on: October 19, 2009, 07:18:23 PM »
I'm really not familiar with Quick Basic, but one thing that might be happening is that QB expects the data to be "far", as well as the code (that is, its address includes both segment and offset - takes up 4 bytes on the stack). Try:

push ds

push descriptor

call far B$PESD

See if that helps...

Best,
Frank

nobody

  • Guest
Re: Mixing nasm and quick basic
« Reply #2 on: October 20, 2009, 02:55:25 PM »
Doesn't work... I'll look for a solution for a while, if i find anything i'll upload...

masm code that works...

-u 1,23
0D87:0001 BA2810        MOV     DX,1028
0D87:0004 8EDA          MOV     DS,DX
0D87:0006 8CD3          MOV     BX,SS
0D87:0008 2BDA          SUB     BX,DX
0D87:000A D1E3          SHL     BX,1
0D87:000C D1E3          SHL     BX,1
0D87:000E D1E3          SHL     BX,1
0D87:0010 D1E3          SHL     BX,1
0D87:0012 FA            CLI
0D87:0013 8ED2          MOV     SS,DX
0D87:0015 03E3          ADD     SP,BX
0D87:0017 FB            STI
0D87:0018 B81A00        MOV     AX,001A
0D87:001B 50            PUSH    AX
0D87:001C 9ACA1D890D    CALL    0D89:1DCA
0D87:0021 B44C          MOV     AH,4C
0D87:0023 CD21          INT     21
-q

Unnassembled MASM code with AFD:
0001 BA9A22         MOV    DX,229A
0004 8EDA           MOV    DS,DX
0006 8CD3           MOV    BX,SS
0008 2BDA           SUB    BX,DX
000A D1E3           SHL    BX,1
000C D1E3           SHL    BX,1
000E D1E3           SHL    BX,1
0010 D1E3           SHL    BX,1
0012 FA             CLI
0013 8ED2           MOV    SS,DX
0015 03E3           ADD    SP,BX
0017 FB             STI
0018 B81A00         MOV    AX,001A
001B 50             PUSH   AX
001C 9ACA1DFB1F     CALL   1FFB:1DCA
0021 B44C           MOV    AH,4C
0023 CD21           INT    21




nasm code... that doesn't work...

-u 1,18
0FD3:0001 C3            RET
0FD3:0002 0F            DB      0F
0FD3:0003 8ED0          MOV     SS,AX
0FD3:0005 BC0001        MOV     SP,0100
0FD3:0008 B8C10F        MOV     AX,0FC1
0FD3:000B 8ED8          MOV     DS,AX
0FD3:000D B81200        MOV     AX,0012
0FD3:0010 50            PUSH    AX
0FD3:0011 9AC41D870D    CALL    0D87:1DC4
0FD3:0016 B44C          MOV     AH,4C
0FD3:0018 CD21          INT     21
-q

Unnassembled NASM code with AFD:
0000 B83522         MOV    AX,2235
0003 8ED0           MOV    SS,AX
0005 BC0001         MOV    SP,0100
0008 B83322         MOV    AX,2233
000B 8ED8           MOV    DS,AX
000D B81200         MOV    AX,0012
0010 50             PUSH   AX
0011 9AC41DF91F     CALL   1FF9:1DC4
0016 B44C           MOV    AH,4C
0018 CD21           INT    21

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Mixing nasm and quick basic
« Reply #3 on: October 23, 2009, 11:32:25 PM »
Bloody useless to try to communicate code on this forum! :(

Outside of an obvious glitch in the first few bytes of one Nasm code disassembly, the main difference I see is in how the stack is set up. The Masm code changes the stack from initial ss:sp to ss=ds, sp=difference * 16. You might try duplicating what the Masm code does with the stack. I don't think it should make it "not work". How does it "not work"? Do you get any output at all?

My attempts to find any information about mixing QB and asm are all about calling asm-written routines from QB, not calling the QB library(?) from asm. If the linker (MS, I presume?) doesn't complain about "unresolved external", it "should work"... I would think...

Try duplicating that weirdness with ss and sp that the Masm code does, and see if that makes any difference...

Best,
Frank