【问题标题】:Issue in cmp statement?cmp 语句中的问题?
【发布时间】:2013-10-06 11:58:10
【问题描述】:

我正在使用 NASM。我认为我的 cmp 语句中存在一些问题,这是数组的第一个索引和一个键之间的简单比较,两者都是相同的,所以它应该打印 Y,但它正在打印 N。如何解决它?

jmp start
array: dw 1,2,3,4,5
key: dw 1
start:

cmp [array],word key
jne not_found
jmp found

found:
mov dx , 'Y';print Y if key is found
jmp end

not_found:
mov dx , 'N';print N if key is not found

end:
mov ah , 2h ;
int 21h ;
mov ah , 0x4c 
int 0x21 ; synonymous to return 0;

【问题讨论】:

  • 您将数组的第一个元素与key的地址进行比较。
  • 如何比较数组的第一个元素和键?

标签: assembly nasm


【解决方案1】:

如何比较数组的第一个元素和键?

; put the value of key in the ax register
mov ax,[key]
; compare the first value in array against ax (i.e. the key)
cmp [array],ax

顺便说一句,而不是

mov ah , 0x4c 
int 0x21 ; synonymous to return 0;

你可以使用:

int 0x20  ; terminate program with errorlevel=0

【讨论】:

  • 将键的值移动到 ax 并不能解决问题。它仍在打印 N。
  • 对我来说很好。我得到 Y 作为输出。您是否确定也更改了cmp
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-04
  • 1970-01-01
相关资源
最近更新 更多