2014-04-11 63 views
0

我有一個問題,理解爲什麼我的cmp語句無法正常工作。裝配不正常

當我運行這個,我在第一個輸入0,它進入storeValue。我輸入0作爲第二個值,它會像它應該的那樣進入searchArray。

我在我的cmp和跳轉語句的斷點和AL的一個表上,所以我不明白爲什麼它存儲的第一個0當它應該提示搜索值在那一點。

感謝您的期待。

.DATA 
prompt1  BYTE "Enter a value to put in array or 0 to search array.", 0 
prompt2  BYTE "Enter a value to search array for.",0       
intArray DWORD ? 
numElem  DWORD 0 
SearchVal DWORD ? 

resultNope BYTE "Not in array.",0 

.CODE 
_MainProc PROC 
      lea  ebx, intArray   ;get the address of array. 
start:  input prompt1, intArray, 50 ;read in integer 
      atod intArray    ;convert to int 

      mov  al, [ebx]    ;move int to register 
      cmp  al, 0     ;if integer is positive - store it! 
      jg  storeValue    ;JUMP! 

      cmp  al, 0     ;if 0 - time to search array! 
      je  searchArray    ;JUMP! 

storeValue: add  numElem, 1    ;Adds 1 to num of elements in array. 
      mov  [ebx], al    ;moves number into array. 
      add  ebx, 1     ;increment to next array address. 
      jmp  start     ;get next number for array. JUMP! 

searchArray:input prompt2, searchVal, 50 ;What are we searching array for? 
      atod searchVal    ;convert to int 
      lea  ebx, intArray   ;get address of array. 
      mov  ecx, 1     ;set loop counter to 1. 

回答

1

您忘記了如何使用inputatod。看着我的水晶球,我猜input需要一個緩衝區來存儲用戶輸入文本,參數50大概是它的大小。請注意,您沒有這樣的緩衝區,甚至沒有50個字節的空間。我也認爲,因爲atod顯然只有1個參數,這是要轉換的文本緩衝區,所以它可能返回eax中的值。這也由你的storeValueal寫道這一事實進一步加強,否則就沒有意義了。

長話短說:

  1. 分配爲輸入的文本
  2. 通過這個數組atod
  3. 不揍al,來電後atod
適當大小的緩衝區

(也適用搜索關鍵詞)

+0

對不起,我是s直到學習80x86 asm,我假設atod和輸入是本書解釋它的標準語法。仔細研究它,我發現它們是宏。雖然謝謝!我明白了,在我從EAX調用atod到[EBX]之後,我愚蠢地忘了移動這個值,從而解決了我的問題。謝謝! – Arcath