Alexander, the exit(2) system call takes a parameter, which is an integer status that the process will return. The value 0 is traditionally a successful return, and anything else signifies an error condition. This assembler is the moral equiv of: char hello[] = { "hello world\n" }; main() { write(1, hello, sizeof(hello)); exit(0); } On Thu, Apr 30, 2020 at 5:50 PM Alexander Voropay wrote: > Can anyone please explain the last $0 pushed to the stack ? > Early SysIII ans SYSV on the i386 (and may be on i286) used > similar syscall convention. > > I wrote about this: > https://minnie.tuhs.org/pipermail/tuhs/2019-October/019274.html > https://minnie.tuhs.org/pipermail/tuhs/2019-October/019294.html > > Example: > === > .file "test.s" > .version "02.01" > .set WRITE,4 > .set EXIT,1 > .text > .align 4 > .globl entry > entry: > pushl %ebp > movl %esp,%ebp > subl $8,%esp > > pushl $14 /length > pushl $hello > pushl $1 /STDOUT > pushl $0 > movl $WRITE,%eax > lcall $0x07,$0 > addl $16,%esp > > pushl $0 > movl $EXIT,%eax > lcall 0x07,$0 > > .data > .align 4 > hello: > .byte 0x48,0x65,0x6c,0x6c,0x6f,0x2c, 0x20,0x77,0x6f,0x72 > .byte 0x6c,0x64,0x21,0x0a,0x00 > > ср, 29 апр. 2020 г. в 17:19, : > > > > Thanks for the link. With that help, I fixed the bug in the program: > > > > mov $6., -(sp) > > mov $1f, -(sp) > > mov $1,-(sp) > > mov $0,-(sp) > > sys 4 > > add $8., sp > > mov $0,-(sp) > > mov $0,-(sp) > > sys 1 > > 1: > > > > > > >> Sorry, I typed that in haste without testing. I don’t have a 2.11 > system > > >> to try it on. However, reading the source code, I did that wrong. The > > >> args go on the stack, not in line with the code. > > >> mov $6, -(sp) > > >> mov a, -(sp) > > >> mov $1,-(sp) > > >> sys 4 > > > > > > Without suggesting that every helpful post should be tested, I find the > > > superb https://unix50.org web emulator excellent for such things. > > > > > > Many thanks to the folks hosting & maintaining this great resource! > > > > > > > > > > >