Mail Archives: djgpp/1997/10/09/13:45:40
From: | "M. Schulter" <mschulter AT value DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | fsdb question: cltd shown as cwd
|
Date: | 9 Oct 1997 16:45:19 GMT
|
Organization: | Value Net Internetwork Services Inc.
|
Lines: | 77
|
Message-ID: | <61j1mv$fo6$1@vnetnews.value.net>
|
NNTP-Posting-Host: | value.net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi, there.
This message is to ask a question about the way that fsdb represents
the `cltd' instruction in an AT&T assembler program for GAS as `cdw'
instead of `cdq' in its Intel (or Intel-like?) disassembly display.
According to
info as machine i386 i386-opcodes
the AT&T `cltd' instruction is equivalent to Intel `cdq': a 32-bit
integer gets sign-extended to 64 bits. So far, I've used this before a
64-bit division, as in the attached brief program.
For some reason, however, fsdb shows the instruction as `cwd' -- which
sign-extends a word to a dword (in other words, a word to a long or
int in GAS terminology).
This happens for me with DJGPP 2.01, using a version of fsdb
(identified on the System Info screen as v. 1.00) with a date for the
executable of 31 October 1996.
Since I'm just learning assembly, I wonder if this is indeed
unexpected behavior in fsdb, a great debugger which I have found
indispensable both in routine learning and bug-detecting.
By the way, my apologies for any infelicities or nonobvious bugs in
the program which follows; when I compile it, fsdb runs it fine, but
displays my `cltd' as `cdw' rather than `cdq'.
Most appreciatively,
Margo Schulter
mschulter AT value DOT net
/*
* cltdtst.s
*
* This file is designed to document an interesting result with
* fsdb version 1.00 distributed with DJGPP v.2.01: the AT&T
* assembly opcode 'cltd' displays as 'cwd' ("sign-extend word
* to double") instead of the expected 'cdq' ("sign-extend dword
* to quad").
*
* To compile, please use the following DJGPP command line:
*
* gcc -o cltdtst.exe cltdtst.s
*
* Margo Schulter mschulter AT value DOT net 8 October 1997
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
.file "cltdtst.s"
.data
string0:
.ascii "\n%d/%d = %d, and %d mod %d = %d\n\0"
.text
.global _main
_main:
pushl %ebp # save stack pointers
movl %esp, %ebp # for `leave' before exiting
movl $-1500000001, %eax # a 32-bit signed dividend
movl %eax, %esi # move a copy of %eax into %esi
movl $3, %ebx # 3 is our divisor
cltd # sign-extend %eax to %edx:%eax
idivl %ebx # and do 64-bit division
pushl %edx # %edx is remainder
pushl %ebx # %ebx is divisor
pushl %esi # %esi has copy of dividend
pushl %eax # %eax is quotient
pushl %ebx # %ebx again has divisor
pushl %esi # %esi again has dividend
pushl $string0 # string includes six format specifiers
call _printf # for our six integers from stack
leave # after _printf, we restore stack frame
ret
- Raw text -