2

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. E.g.

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
  • I don't know this environment, but you might be suffering from buffering. Many environments are line-buffered and empty the buffer on a new-line '\n'. Try appending a '\n' to the last printf. – cdarke Jun 30 '11 at 13:05
  • Thanks, but that doesn't solve that. – Vladimir F Героям слава Jun 30 '11 at 14:07
  • This is just a shot in the dark, but does `mmix-gcc hellommix.c -o hellommix` followed by `mmix hellommix "abc"` work better ? (that matches more closely with the example in the link you posted, and is in line with the caution : __Caution: do not ever use relative paths (../dir), always use absolute paths (/path/to/dir)__) – Sander De Dycker Jul 04 '11 at 21:53

2 Answers2

2

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]);
}
Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
  • Thank's for suggestions. Regrettably, nothing better. Maybe thare is some regression in gcc-4.6 for mmix. For code with your for loop i get output "arg arg hello," , i.e. even no newline gets printed. – Vladimir F Героям слава Jun 30 '11 at 15:49
  • Strange. I would think then that glibc (or of not glibc, the C-library on your platform) is buggy, not gcc itself. Maybe try the appropriate bug trackers or mailing lists? – Sebastian Mach Jul 01 '11 at 07:57
  • On another note: Is mmix support considered mature by the developers? (just a side-thought) – Sebastian Mach Jul 01 '11 at 07:58
  • No, not mature at all. Maybe it is broken in the newer release of gcc. – Vladimir F Героям слава Jul 01 '11 at 09:14
  • @VladimirF: I'd guess that it's more likely a libc implementation problem, perhaps mixing up `exit(3)` with the raw system call `_exit(2)` or `exit_group(2)` which doesn't flush buffers. (This is a somewhat common problem in hand-written asm when people call printf, especially without a trailing newline to flush in line-buffered mode, and then exit with a raw asm system call, not `call exit`). Anyway, I hope the compiler / library has been fixed in the 10 years since this question was asked! – Peter Cordes Aug 10 '21 at 03:46
0

Enter code:

setbuf(stdout,NULL); 

after variable declaration.

Like this, just add setbuf(stdout,NULL); this code. On the first top only. Then you can do the code.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253