Hi nobody... Hi Debs! - Hey, nobody, you lured Debs into the discussion! Kewl!!!
Drat, you fixed your typo before I got to it. Gotta be quick! :)
I'm going to give a different answer, though. The trick is "dereferencing the pointer"... (I think that's what they call it over at the University)
SEGMENT data
K db 30H, 31H, 32H
KPtr resw 1
Strictly speaking, you shouldn't use "res*" in an initialized section. In "-f obj" output format, Nasm lets it slide, but in any(?) other output format, it wails, "Attempt to reserve space in an uninitialized segment - zeroing" (or some such). It's a worse problem to attempt to initialize data/code in an uninitialized section (".bss", in output formats that "know" that name - Masm calls it ".data?", I think). Nasm truely "ignores" that! Since I don't know how to create an uninitialized section in Nasm (except a section with all "res*" data, if it's last, doesn't add anything to the file size), let it go - "dw 0" would do the same thing...
> now I thought I'd put KPtr to point to K like this:
You don't show the "mov ax, data"/"mov ds, ax" part. I assume you do so...
mov AX, K
mov WORD [KPtr], AX
So far, so good... You could also have initialized it: "Kptr dw K"...
mov DL, [KPtr] ; RONG
But *this* moves the low byte of the address of K into dl, not the byte at [K]!
mov bx, [Kptr]
mov dl, [bx]
(can't be "just any register", for 16-bit instructions, must be bx, si, or di - bp would work, but [bp] defaults to [ss:bp] and we'd have to use an override - [ds:bp]. 16-bit "effective address" rules are a royal PITA - being able to forget 'em is the best thing about graduating to 32-bit code!)
call DisplayChar
add BYTE [bx], 01H
mov DL, [bx]
call DisplayChar
mov DL, [bx+1]
call DisplayChar
mov DL, [bx+2]
call DisplayChar
mov AX, 4C00H
int 21H
As Debs points out, you don't really need "Kptr" for this - don't really need bx, either, "mov dl, [K + 1]", etc. would also work. But remember that "Kptr" is the address of Kptr, [Kptr] is the "[contents]" of Kptr - the address of K. "[[Kptr]]" won't work to give us the contents of K, however! Gotta do the "mov reg, [Kptr]"/"mov dl, [reg]" thing. In Masm, things are different: "Kptr" means "[contents]", "offset Kptr" is the address. The actual "ptr" keyword is "syntactic fluff" that doesn't do a damn thing - what else would it be???
I've been known to tell people reading AoA that it's okay to use Masm - just wash your hands after! :) These days, there's a better solution (if your objections to Masm are "political"). Japheth has forked OpenWatcom's Wasm into Jwasm - more compatible with Masm. I *think* it should be a drop-in replacement for Masm...
http://www.japheth.de/JWasm.htmlIt even does ELF, so it's *better* than Masm - you don't even need to use their damn OS! The syntax is still uglier than ours, though. :)
Best,
Frank