2009-11-04 36 views
0
.section .data 
msgI: 
.ascii "x = y\n" 
msgI_end: 


msgM: 
.ascii "x > y\n" 
msgM_end: 


msgL: 
.ascii "x < y\n" 
msgL_end: 


.section .text 
.globl main 
main: 
    movl $5, %eax   #x = 5 
    movl $5, %ebx   #y = 10 
    cmp %ebx, %eax 

    je IGUAL 

    jg MAYOR 

    jl MENOR 

IGUAL:      #Esta seccion de cogido se encarga 
    movl $4, %eax   #de imprimir si x = y usando  
    movl $1, %ebx   #los system calls de Linux  
    pushl $msgI 
    call printf    
    #movl $size, %edx   
    int $0x80       
    jmp EXIT 

MAYOR:      #Esta seccion de cogido se encarga 
    movl $4, %eax   #de imprimir si x > y usando  
    movl $1, %ebx   #los system calls de Linux  
    pushl $msgM 
    call printf    
    #movl $size, %edx   
    int $0x80       
    jmp EXIT 

MENOR:      #Esta seccion de cogido se encarga 
    movl $4, %eax   #de imprimir si x < y usando  
    movl $1, %ebx   #los system calls de Linux  
    pushl $msgL 
    call printf    
    #movl $size, %edx   
    int $0x80       
    jmp EXIT 

EXIT: 
    movl $1, %eax   #System calls para salir del programa 
    int $0x80 
+0

因此它不按預期打印msgI? – 2009-11-04 22:40:19

+0

有問題嗎? – bluebrother 2009-11-04 22:46:30

回答

2
movl $5, %ebx     #y = 10 

碼不匹配的評論。

int $0x80             
    jmp EXIT 

你爲什麼要調用中斷? printf已經完成打印,並覆蓋了像%eax這樣的寄存器。

現在,你將你的信息混雜在一起的原因:printf需要一個NUL終止的字符串。如果它沒有看到'\0',它會繼續。

解決方案:在您的msg*字符串末尾添加一個\0。然後printf將停止打印。

+0

我之前就忘記了這一點,但是如果您使用NASM:使用'.asciiz「abc」'相當於'.ascii「abc \ 0」'。你選擇哪個取決於你。 – ephemient 2009-12-02 22:36:04