michael1@ihlpf.UUCP (Pula) (01/12/87)
HELP! I'm trying to interface Turbo Pascal with Microsoft Macro
Assembler. Here is the scenario:
Interrupt Service Routine - written in Assembler.
Screen Handler - written in Turbo.
ISR collects data from serial port and needs to write into a
buffer which is accessible from Turbo.
Can (and do you have an example) the ISR be written and externally
assembled (linked & exe2bin'd) and then be made external to the
Turbo program? Writing inline code with Turbo is really a drag!
Your help is greatly appreciated!
mike
ihnp4!ihlpf!michael1
(312)510-6449
--
Mike
!ihnp4!ihlpf!michael1mmm@nbires.UUCP (01/16/87)
Turbo and masm are not the easiest things to use together but it
can be done if you know a few tricks. The first and perhaps most
important one is how to debug under turbo pascal.
first you must load turbo under a debugger (i'll use symdeb as an
example)
symdeb turbo.com
after the debugger loads, type 'g' to get turbo started. when you
want to hit a breakpoint, just compile you code with an inline($cc);
statement in your code (and int 3) which will cause the debugger to
become active. set the ip to the next instruction (ip := ip+1) in
order to continue.
MASM:
the biggest problem is finding your data. you can use the 'external xx.bin;'
syntax to include you own assembly code in a binary format but the code
must be totaly relocatable. this means you cannot access any direct offsets.
for example 'mov ax,cs:x' would not work because masm assumes a starting
address of 0. parameters in the mov instruction are absolute references
(unlike jumps and calls).
to work around this problem you will need to use a base register to
access your data. All references will have to be based off this register.
here is an example of how to write a routine:
code segment para public 'CODE'
assume cs:code, ds:nothing ;forces all references to be cs:
jmp start
data label word
xx dw ?
yy dw ?
start: push bp
mov bp,sp ;save the stack
call next ;get our instruction pointer
next: pop bx ;in bx
sub bx,offset next ;make bx point to the start of
;this piece of code.
;to reference data, you need to always use the bx register
mov ax,word ptr xx[bx]
;to get the address of a variable
lea si,xx[bx]
code ends
end
hope this helps,
lloyd w. tabb
nbi engineering
3450 mitchell lane
boulder, colorado 80301
{hao|ucbvax|allegra}!nbires!mmm