The following code is a test code which should simply read the first
byte of an integer and of a string, using direct memory access.
The assembler part should perform exactly the same operation as the
DEF SEG / PEEK lines, but it does not!
Could anybody tell me what is wrong with this code, or if there is a
bug in the inline assembler?
This is the code:
DEFINT A-Z
CLS
test$ = "This is a test string."
test2 = &H5564
segm1 = STRSEG(test$): pointer1 = STRPTR(test$)
segm2 = VARSEG(test2): pointer2 = VARPTR(test2)
scrptr = 0
DEF SEG = segm1
peek1? = PEEK(pointer1)
DEF SEG
DEF SEG = segm2
peek2? = PEEK(pointer2)
DEF SEG
! PUSHF
! PUSH AX
! PUSH DS
! PUSH SI
! MOV AX, segm1
! MOV DS, AX
! MOV SI, pointer1
! MOV AX, DS:[SI]
! MOV asm1?, AL
! MOV AX, segm2
! MOV DS, AX
! MOV SI, pointer2
! MOV AX, DS:[SI]
! MOV asm2?, AL
! POP SI
! POP DS
! POP AX
! POPF
PRINT peek1?, asm1?
PRINT peek2?, asm2?
END
The expected result would be:
84 84 (ASCII code for "T")
100 100 (= &H64)
But it was:
84 0
100 0
When tracing the program line by line, I found that after the lines
MOV SI, pointer1, MOV DS, AX (second time), and MOV SI, pointer2
the values in DS resp. SI were zero.
Can anybody help?
Hans Ruegg
byte of an integer and of a string, using direct memory access.
The assembler part should perform exactly the same operation as the
DEF SEG / PEEK lines, but it does not!
Could anybody tell me what is wrong with this code, or if there is a
bug in the inline assembler?
This is the code:
DEFINT A-Z
CLS
test$ = "This is a test string."
test2 = &H5564
segm1 = STRSEG(test$): pointer1 = STRPTR(test$)
segm2 = VARSEG(test2): pointer2 = VARPTR(test2)
scrptr = 0
DEF SEG = segm1
peek1? = PEEK(pointer1)
DEF SEG
DEF SEG = segm2
peek2? = PEEK(pointer2)
DEF SEG
! PUSHF
! PUSH AX
! PUSH DS
! PUSH SI
! MOV AX, segm1
! MOV DS, AX
! MOV SI, pointer1
! MOV AX, DS:[SI]
! MOV asm1?, AL
! MOV AX, segm2
! MOV DS, AX
! MOV SI, pointer2
! MOV AX, DS:[SI]
! MOV asm2?, AL
! POP SI
! POP DS
! POP AX
! POPF
PRINT peek1?, asm1?
PRINT peek2?, asm2?
END
The expected result would be:
84 84 (ASCII code for "T")
100 100 (= &H64)
But it was:
84 0
100 0
When tracing the program line by line, I found that after the lines
MOV SI, pointer1, MOV DS, AX (second time), and MOV SI, pointer2
the values in DS resp. SI were zero.
Can anybody help?
Hans Ruegg
Comment