簡體   English   中英

額外推動 OpenWatcom 內聯匯編

[英]Extra push in OpenWatcom inline assembly

我正在用 OpenWatcom V2 wcc編譯這個 C 源代碼:

/* Writes a '\0'-terminated string to the file descriptor. */
static void fdputs(int fd, const char *s);
#pragma aux fdputs = \
"push si" \
"mov cx, -1" \
"repz scasb" \
"neg cx" \
"inc cx"  /* now cx is the number of bytes to write */ \
"pop dx"  /* now dx points to the buffer (s argument) */ \
"mov ah, 0x40" /* WRITE */ \
"int 0x21" \
parm [ bx si ] \
modify [ ax cx dx si ];  /* Also modifies cf */

int myfunc(void) {
  fdputs(1, "Hello!");
  return 0;
}

在 wcc 生成的 .obj 文件的 disassebly 中,6 個push和 5 個pop不平衡。 (代碼在運行時會因此而崩潰。)

$ wcc -bt=dos -ms -s -os -W -w4 -wx -we -wcd=202 -0 -fr -fo=t.obj t.c
$ wdis -a -fi -i=@ t.obj
.387
                PUBLIC  myfunc_
                EXTRN   _small_code_:BYTE
DGROUP          GROUP   CONST,CONST2,_DATA
_TEXT           SEGMENT BYTE PUBLIC USE16 'CODE'
                ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP
myfunc_:
        push            bx
        push            cx
        push            dx
        push            si
        mov             ax,offset DGROUP:@$1
        push            ax
        mov             bx,1
        xor             si,si
        push            si
        mov             cx,0ffffH
        repe scasb
        neg             cx
        inc             cx
        pop             dx
        mov             ah,40H
        int             21H
        xor             ax,ax
        pop             si
        pop             dx
        pop             cx
        pop             bx
        ret
_TEXT           ENDS
CONST           SEGMENT WORD PUBLIC USE16 'DATA'
@$1:
    DB  48H, 65H, 6cH, 6cH, 6fH, 21H, 0

CONST           ENDS
CONST2          SEGMENT WORD PUBLIC USE16 'DATA'
CONST2          ENDS
_DATA           SEGMENT WORD PUBLIC USE16 'DATA'
_DATA           ENDS
                END

我是否正確使用了 wcc 內聯程序集? 這可能是wcc中的錯誤嗎?

我相信這是 OpenWatcom C/C++ 的一個錯誤,因為我過去曾觀察到這種行為。 為了解決這個問題,我在它們自己的[]之間分別列出了每個參數。 嘗試修改:

parm [ bx si ] \

成為:

parm [ bx ] [ si ] \

生成的代碼應如下所示:

.387
                PUBLIC  myfunc_
                EXTRN   _small_code_:BYTE
DGROUP          GROUP   CONST,CONST2,_DATA
_TEXT           SEGMENT BYTE PUBLIC USE16 'CODE'
                ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP
myfunc_:
        push            bx
        push            cx
        push            dx
        push            si
        mov             si,offset DGROUP:@$1
        mov             bx,1
        push            si
        mov             cx,0ffffH
        repe scasb
        neg             cx
        inc             cx
        pop             dx
        mov             ah,40H
        int             21H
        xor             ax,ax
        pop             si
        pop             dx
        pop             cx
        pop             bx
        ret
_TEXT           ENDS
CONST           SEGMENT WORD PUBLIC USE16 'DATA'
@$1:
    DB  48H, 65H, 6cH, 6cH, 6fH, 21H, 0

CONST           ENDS
CONST2          SEGMENT WORD PUBLIC USE16 'DATA'
CONST2          ENDS
_DATA           SEGMENT WORD PUBLIC USE16 'DATA'
_DATA           ENDS
                END

刪除了使用AX寄存器來傳輸const char *s的地址以及沒有與之關聯的相應pop的額外push ax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM