Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!ihnp4!ihlpa!jimx From: jimx@ihlpa.ATT.COM (Harris) Newsgroups: comp.sys.ibm.pc Subject: Passing pointers in C to 8086 assembler Message-ID: <7759@ihlpa.ATT.COM> Date: 26 Apr 88 20:25:14 GMT Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 61 I'm getting myself confused, and need some pointers (pun intended) on passing pointers from a C function to an 8086 assembly language procedure. Let's assume that I pass a pointer to a string of unknown length, and that the asm procedure then copies that string to a local variable: C: char msg[80]; foo( msg ); ASM, leaving out header stuff: local_msg db 80 dup (0) _foo proc near push bp mov bp, sp push di push si Here's where I get confused. My pointer (16-bit offset, I believe) is at [bp+4]. How do I address the second character of msg[]? [bp+5] is one address above [bp+4], right? Or is it the address pointed to by bp+5? If I want msg[4], how do I address it? ex: does [si+cx] = [bp+4+cx]?? mov si, [bp+4] mov di, local_msg mov cx, 4 mov al, [si+cx] mov [di+cx], al or graphically: ____ ____ bp+4 -->|____|-->[bp+4]---->|____| |____| |____| |____| |____| |____| |____| bp+4+4 -->|____|-->[bp+8]-->? |____|<--[bp+4][4] == [bp+4+4]??? I think we can agree that obviously [bp+8] is not the same thing as [bp+4]+4. But the book I have seems to imply that [bp+4][4] is the same as [bp+4+4], which I have trouble accepting. So what is the solution? If you have a good reference for passing pointers to assembly language, please let me know. I have "Supercharging C with Assembly Language", by Chesley and Waite. I haven't found where (if) they deal with this, so even a page reference would help. The more I look at this, the more confusing it seems to get! --- As an alternative, how can I get a segment:offset pair for a variable to put into the dos.h register structures? If I could do this, it would solve my problem. --- Thanks in advance, and you can email me or post, as you like. Jim Harris ihlpa!jimx