2015-12-12 19 views
0

我得到的麻煩有兩個chars- 的scanf函數(%C,%C) 我試戴如何SCANF在連續兩個字符 - 組裝%C%C

subl $4,  %esp   
pushl %esp     
pushl "%c %c"   
call scanf    
leal (%esp), %ebx  
movzbl (%ebx), %ebx  

這個 - 會 - 掃描2個字符在EBX中?

我需要讓他們兩個到一個註冊? 謝謝。

回答

1

不,它不會。由於scanf()缺乏參數,可能會導致一些不好的結果。

試試這個:

subl $4,  %esp # allocate a buffer 
leal 1(%esp), %ebx 
pushl %ebx   # where to store the second character 
decl %ebx 
pushl %ebx   # where to store the first character 
pushl $str1 
call scanf 
add  $12,  %esp # discard the arguments 
movzwl (%esp), %ebx 
addl $4,  %esp # discard the buffer 

# put this where won't be executed 
str1: .asciz "%c %c" 

這個程序將存儲的第一個字符到最低顯著字節,第二個字符至第二個最低顯著字節。

demo