Thank you very much... now as I see the answer, it is really obvious!
The reason I used DS was that the original program would then use
REP MOVSB in order to copy the string to a different memory location,
so DS:SI must necessarily point to the string's content when it comes
to that step. I suppose I can follow your suggestion and then safely
copy ES to DS when I do not longer need to access any PB variables
directly?
(Sorry, I do not have the PB compiler and internet access at the same
place, so I can't test it just now.)
Hans Ruegg.
Announcement
Collapse
No announcement yet.
Inline assembler bug? (Very simple question)
Collapse
X
-
When accessing PB vars using ASM, DS must be restored prior to accessing it.
You should use ES: DI, instead of DS: SI.
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 ES ! PUSH DI ! MOV AX, segm1 ! MOV ES, AX ! MOV DI, pointer1 ! MOV AX, ES:[DI] ! MOV asm1?, AL ! MOV AX, segm2 ! MOV ES, AX ! MOV DI, pointer2 ! MOV AX, ES:[DI] ! MOV asm2?, AL ! POP DI ! POP ES ! POP AX ! POPF PRINT peek1?, asm1? PRINT peek2?, asm2? END
Peter.
mailto[email protected][email protected]</A>
[This message has been edited by Peter Lameijn (edited January 03, 2001).]
Leave a comment:
-
-
Hans,
the DS register is used to locate the data (pointer1 and pointer2) within the data segment but you have overwritten DS before the data is looked at so the wrong segment value is used and the wrong pointer value is looked up. Replace all occurrances of DS with ES in your code and it'll work as expected.
Paul.
Leave a comment:
-
-
Inline assembler bug? (Very simple question)
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
Tags: None
-
Leave a comment: