S1.geti, S2.geti all call the same procedure (call it Sc_geti). S1.i not available. Strange chars

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



S1.geti, S2.geti all call the same procedure (call it Sc_geti). S1.i not available. Strange chars



S1.geti, S2.geti, and S3.geti all call the same procedure (call it Sc_geti). How does Sc_geti differentiate between S1.i, S2.i, and S3.i?



I can't print S1.geti.


.MODEL SMALL
.DATA
MSG1 DB "Message1:... ",'$'
MSG2 DB "Message2:... ",'$'
MSG3 DB "Message3:... ",'$'

dseg segment byte public 'data'
_THIS equ es:[bx]
Sc_geti proc far
mov ax, _THIS.i
ret
Sc_geti endp

Sc struc
i dw ?
j dw ?
c dd ?
geti dd Sc_geti
Sc ends

S1 Sc <1,1,1,>
S2 Sc <2,'2','2',>
S3 Sc <'3','3','3',>
dseg ends
;
cseg segment byte public 'CODE'
assume cs:cseg, ds:dseg, es:dseg
main:
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1 ;print msg1
MOV AH,09H
INT 21H

mov bx, seg S1
mov es, bx
mov bx, offset S1

MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1 ;print msg1
MOV AH,09H
INT 21H

call S1.geti

MOV AX,@DATA
MOV DS,AX
LEA DX,MSG3 ;print msg3
MOV AH,09H
INT 21H


CMP AL,13 ;ascii for "ENTER" key
JE EXIT
MOV DL,0AH ;moving the content of AH into dl to print it
MOV AH,02 ;code to print a character
INT 21H

EXIT:
MOV AH,4CH
INT 21H
END

cseg ends



OUTPUT: Message1:...Message1:...
I try understand this document:
http://www.drdobbs.com/embedded-systems/object-oriented-programming-in-assembly/184408319 (Example 10).


Message1:...Message1:...


.MODEL SMALL
.DATA
MSG1 DB "Message1:... ",'$'
MSG2 DB "Message2:... ",'$'
MSG3 DB "Message3:... ",'$'
MSG4 DB "Message4: INSIDE Sc_geti ",'$'
;
cseg segment byte public 'CODE'
assume cs:cseg, ds:dseg, es:dseg
_THIS equ es:[bx]
Sc_geti proc far
mov ax, _THIS.i
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG4 ;print msg4
MOV AH,09H
INT 21H
MOV DX,_THIS.i ;moving the content
MOV AH,02 ;code to print a character
INT 21H
ret
Sc_geti endp
cseg ends

dseg segment byte public 'data'

Sc struc
i dw ?
j dw ?
c dd ?
geti dd Sc_geti
Sc ends

S1 Sc <'1','1',1,>
S2 Sc <2,'2','2',>
S3 Sc <'3','3','3',>

dseg ends

cseg segment byte public 'CODE'
assume cs:cseg, ds:dseg, es:dseg

main:
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1 ;print msg1
MOV AH,09H
INT 21H

mov bx, seg S1
mov es, bx
mov bx, offset S1

MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1 ;print msg1
MOV AH,09H
INT 21H

call S1.geti

MOV AX,@DATA
MOV DS,AX
LEA DX,MSG3 ;print msg3
MOV AH,09H
INT 21H

MOV AH,4CH
INT 21H
END

cseg ends



OUTPUT: Message4 : INSIDE Sc_geti =t v...(a lot "strange chars)





It uses es:bx set by the caller. Also you forgot to actually read keyboard input before the cmp al,13. Nevertheless that should not give you an endless loop (which is what you get if I understood you correctly). Learn to use a debugger so you can single step the code. PS: why is your Sc_geti in dseg?
– Jester
Aug 8 at 11:11



es:bx


cmp al,13


Sc_geti


dseg





I think this is problem with _THIS equ es:[bx], I change into: call Sc_geti and program ran successfully.
– supermario
Aug 8 at 11:44



call Sc_geti





Hmm... when I put Sc_geti to cseg i got error: A2017 Forward reference illegal in this line geti dd Sc_geti
– supermario
Aug 8 at 12:00



A2017 Forward reference illegal


geti dd Sc_geti





Put the whole data segment after the code. Also you should be able to switch back and forth between segments if you like that better. I find it unlikely that changing the _THIS would make it work, in fact it should not even assemble then because mov ax, _THIS.i would not be valid. Note that LOOP uses CX as counter you just want a JMP. So what exactly happens with the latest code in the question?
– Jester
Aug 8 at 12:31


_THIS


mov ax, _THIS.i


LOOP


CX


JMP





When I put the whole data segment after code I got severeal error: Symbol not defined
– supermario
Aug 8 at 12:53


Symbol not defined









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard