2012-07-17 89 views
0

我已經用Gnu管理'Hello World'!

那麼,接下來的事情是打印1到10吧? (也許在紅寶石)

現在,我會很高興打印A緊跟着B.這就是我的。

.section .text 
    .globl _start 

_start: 
    # Print A 
    movl $4,%eax 
    pushl $0x41 
    movl %esp,%ecx  # Would rather movl $0x41,%ecx 
    movl $1,%ebx 
    movl $1,%edx 
    int $0x80 

    # Closely followed by B 
    movl $4,%eax 
    incl (%esp)   # Rather incl(%ecx) here 
    movl %esp,%ecx 
    movl $1,%ebx 
    movl $1,%edx 
    int $0x80 

    movl $1,%eax 
    movl $0,%ebx 
    int $0x80 

而且它的實際工作,但我的問題是,爲什麼我不能

movl $0x41,%ecx 

首先,然後

incl (%ecx) 

待會兒嗎?

+0

這是不一樣的。它看起來像'ecx'被用作某種基本指針。 – Mysticial 2012-07-17 01:25:14

+0

@Mysticial寫入聲明爲:'ssize_t write(int fd,const void * buf,size_t count)',ecx爲buf – bluekeys 2012-07-17 01:42:26

回答

0

對於sys_write,%ecx希望指向字符或字符駐留在內存中的位置,而不是「要」打印的字符。 「incb」可能比「incl」更正確,因爲你只增加一個字節 - 「(%esp)」或「(%ecx)」應該工作,因爲它們指向同一個地方。請注意,您正在增加內存的「內容」,而不是指向內存的指針。

最好, 弗蘭克

+0

謝謝Frank。這很有道理。 – bluekeys 2012-07-17 15:24:08

相關問題