简体   繁体   中英

Printf problem with gcc on mmix

I have compiled the gcc 4.6.0 for mmix according to http://www.bitrange.com/mmix/install.html . After I try their simple hello world, or any other call to printf with more than the first string, only the first string gets printed. Eg

lada@:~/f/c> cat hellommix.c
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
  printf ("hello, %s\n", argc > 1 ? argv[1] : "world");
  exit (0);
}

lada@:~/f/c> mmix-gcc hellommix.c 
lada@:~/f/c> mmix ./a.out "abc"
hello, lada@:~/f/c> 

The generated assembly looks like this:

# 1 "hellommix.c"
! mmixal:= 8H LOC Data_Section
        .text ! mmixal:= 9H LOC 8B
        .section        .rodata
        .p2align 2
        LOC @+(4-@)&3
LC:0    IS @
        BYTE "world",#0
        .p2align 2
        LOC @+(4-@)&3
LC:1    IS @
        BYTE "hello, %s",#a,#0
        .text ! mmixal:= 9H LOC 8B
        .p2align 2
        LOC @+(4-@)&3
        .global main
main    IS @
        SUBU $254,$254,24
        STOU $253,$254,16
        ADDU $253,$254,24
        GET $2,rJ
        SET $3,$0
        SUBU $0,$253,24
        STOU $1,$0,0
        SUBU $0,$253,12
        STTU $3,$0,0
        SUBU $0,$253,12
        LDT $0,$0,0
        SLU $0,$0,32
        SR $0,$0,32
        CMP $0,$0,1
        BNP $0,L:2
        SUBU $0,$253,24
        LDO $0,$0,0
        LDO $0,$0,8
        JMP L:3
L:2     IS @
        GETA $0,LC:0
L:3     IS @
        GETA $5,LC:1
        SET $6,$0
        PUSHJ $4,printf
        PUT rJ,$2
        SETL $5,0
        PUSHJ $4,exit

        .data ! mmixal:= 8H LOC 9B

Try those:

  • put a fflush (stdout); before exiting. (though normally, posix' man 3 exit tells that all buffers are flushed; maybe something mmix specific)
  • Dump all arguments, just to see what's there.

-

for (int x=0; x!=argc; ++x) {
    printf ("arg %d: \"%s\"\n", x, argv[x]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM