I have some pieces of code for dev86/bcc (mostly inline assembly), both of them are working fine. Now I'm trying to use this with nasm, but my code won't work.
Maybe some of you guys can help me.
First, the working C code:
Code: Select all
uint16_t get_mem(uint16_t seg, uint16_t off) {
#asm
mov bx, sp
mov es, [bx+2] ; seg
mov bx, [bx+4] ; off
seg es
mov ax, [bx]
#endasm
}
/* write a 16bit word to an absolute location in SEG:OFF format */
void set_mem(uint16_t seg, uint16_t off, uint16_t data) {
#asm
mov bx, sp
mov es, [bx+2] ; seg
mov ax, [bx+6] ; data
mov bx, [bx+4] ; off
seg es
mov [bx], ax
#endasm
}
Code: Select all
; get a 16bit word from an absolute location in SEG:OFF format
; takes SEG:OFF in DX:AX
; returns data in AX
get_mem:
pusha
mov bx, ax ; off to bx
mov es, dx
mov ax, [es:bx]
popa
ret
; takes SEG:OFF in DX:AX
; takes data in BX
set_mem:
pusha
mov bx, ax ; off to bx
mov es, dx
mov [es:bx], ax
popa
ret
There should be a word (0x3456) written at 0x0570. After reading the same memory location, function print_hex16 (input in AX) prints 0x0070, the value that was written to AX before the call to get_mem.
Code: Select all
mov dx, 0x0050
mov ax, 0x0070
mov bx, 0x3456
call set_mem
mov dx, 0x0050
mov ax, 0x0070
call get_mem
mov bx, 0x07 ; default attribute
call print_hex16
sdose