简体   繁体   中英

Conditional Jump (jg) after comparison (cmp)

Here is a snippet of code that my book provided. The question asks whether the execution bx,1 or ax,10 will be executed. Looking at the code I want to say Ax,10 will be executed, an answer online says bx,1 will be executed, and my emulator says both are executed. Will someone help me understand what is really going on here?

mov cx,5
not cx
mov dx,10
cmp cx,dx
jg jump1
mov bx,1
jump1:
mov ax,10

Let's trace. Before the CMP line the value of CX is -6 (the result of NOT on 5). The JG command performs a signed comparison - it doesn't treat negative numbers as large positive ones (JA and JB do).

So CX (-6) is not greater than DX (10), and the conditional jump is not taken. So both lines execute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM