ASM Courtesy of Mischief

[11:41 PM] mischief: @Henesy (Sean) run 6c -S on a program.
[11:41 PM] mischief: have you read asm.ps?
[11:44 PM] mischief: basically you write TEXT func(SB), $1234
[11:45 PM] mischief: func being name,  1234 is the reserved stack space
[11:45 PM] mischief: movs mnemonics have the size built into them rather than the registers
[11:45 PM] mischief: so MOVL $2, AX loads 2 into EAX
[11:45 PM] mischief: L being 'long', or 32 bits
[11:46 PM] mischief: generally B is byte, W is short, L is long, Q is quadword or 64 bits
[11:46 PM] mischief: sometimes 'O' appears which is for sse registers on x86/amd64
[11:47 PM] mischief: you also need to understand the calling convention
[11:47 PM] mischief: first arg on amd64 is passed through ebp, or 'BP'
[11:47 PM] mischief: its conventionally called RARG though
[11:48 PM] mischief: so MOVL RARG, BX is move the first argument to ebx
[11:48 PM] mischief: other arguments are on the stack, 8 byte aligned relative to SP
[11:49 PM] mischief: so e.g. MOVQ 8(SP), DX would move 64bits second argument into edx
[11:50 PM] mischief: here's a really dumb memcpy i wrote recently while benchmarking different memcpy implementations
[11:50 PM] mischief:
TEXT memcpymovsb(SB), $-4
	MOVQ    RARG, DI    /* destination */
	MOVQ    src+8(FP), SI    /* source */
	MOVL    n+16(FP), CX    /* n bytes */
TEXT movsbinner(SB), $0
	MOVQ    DI, AX        /* return value */
	CLD
	REP; MOVSB
	
	RET
[11:51 PM] mischief: ignore the -4, it has no effect
[11:51 PM] Henesy (Sean): thank you so much
[11:51 PM] Henesy (Sean): this is what i needed i think
[11:51 PM] mischief: the c function signature for this assembly code is like memcpy
11:51 PM] mischief: void *memcpy(void *to, void *from, ulong n)
11:52 PM] mischief: oh yeah and eax is the return value for pointers/integers
11:52 PM] mischief: i think doubles/floats are returned in an fp register
11:52 PM] mischief: you can run 6c -S on some of the code in /sys/src/libc/port to see how things usually work there
[11:52 PM] mischief: but again this is all explained for the most part in asm.ps
11:53 PM] mischief: you can also look at /sys/src/9/pc64/l.s and /sys/src/libc/amd64/*.s for some actual assembly
[11:53 PM] mischief: but tbh writing assembly on plan9 is largely useless
[11:53 PM] mischief: its on purpose that there isn't much