char_out:
# Allocate 8 bytes on the stack by subtracting 8 from the stack pointer.
#
# This is done for conformance to the calling convention expected by the
# 'putchar' function, which we're about to call.
subq $8, %esp
# This is the weirdo AT&T mnemonic for the MOVSX instruction, which does a
# move with sign extension. This means that it extends a small value
# (here, a BYTE-sized value in DIL) into a larger value (here, a
# DWORD-sized value in EDI), in a way that properly accounts for the
# value's sign bit.
#
# This is necessary because the 'putchar' function expects to be passed a
# 32-bit 'int' parameter.
movsbl %dil, %edi
# It's obvious what this does: it calls the 'putchar' function.
call putchar
# Clean up the stack, undoing what we previously did to the stack pointer
# at the top of the function (the 'subq' instruction).
addq $8, %rsp
由於Lashane已經評論說,這彙編代碼相當於下面的C代碼:
void char_out(char P1)
{
putchar(P1);
}
或者,我想你也可以說:
void char_out(char P1)
{
int temp = (int)P1; // movsbl
putchar(temp);
}
但是C編譯器會爲你隱式執行,所以沒有必要明確地顯示擴展轉換。
它只是'putchar(P1);' –
詢問某人做你的工作的問題不適用於StackOverflow。向我們展示您迄今爲止所嘗試的內容以及您遇到困難的地方,我們很樂意爲您提供幫助。 –
@olivercharlesworth這是一個很好的笑話,但你爲什麼改變鏈接? –