X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: eplmst AT lu DOT erisoft DOT se (Martin Stromberg) Newsgroups: comp.os.msdos.djgpp Subject: Re: ASM syntax Date: 14 Jan 2002 17:00:50 GMT Organization: Ericsson Erisoft AB, Sweden Lines: 41 Message-ID: References: NNTP-Posting-Host: lws256.lu.erisoft.se X-Newsreader: TIN [version 1.2 PL2] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Andrew Fairburn (a DOT j DOT fairburn AT durham DOT ac DOT uk) wrote: : ive been writing a function in assembler code for a real mode callback. The : code needs to take the ss:sp, of where the program was when this interupt : function is called, from the register pair ds:si then. It uses this to read : the cs:ip address left on the stack when the interupt was called and then : places it back in a memory address pointed to by the register pair es:di. It : then returns with an IRET. unfortunatley my code doesnt work:- : cld : lodsw : movw %ds:(%esi), %ax // gets ss:sp which should point to old IP on : stack I'm not an assembly guy but lodsw followed by movw %ds:(%esi), %ax? Isn't one of them redundant? : movw %ax, %es:44(%edi) //mov IP into mem structure 44 b disp from : es:di : lodsw : movw %ds:2(%esi), %ax // gets CS which is 2 bytes disp from IP on : stack : movw %ax, %es:46(%edi) // move into mem structure : movw %ds:2(%esi), %ax : movw $0x1b0, %dx : outb %dx : The thing im unsure about is the syntax for addressing memory e.g. : %ds:2(%esi), i thought this would take the selector and offset address in : ds:si and then move on 2bytes and return the value there. Is my : understanding of the displacement, i.e. 2, correct? Nope. It'll take what is at the offset %esi+2 in the segment indicated by %ds. Note that DI != EDI. Plus it won't automatically adjust %esi; that's what lodsw and stosw (except one of them uses %esi instead of %edi) do. Right, MartinS