下面的代码无法正常工作如何检查给定的数字是i386的汇编语言正或负
cmp ax, 0 jl NegativeNumber ;jump to negative statements
test ax , 0x80 ;to compare sign bit. but it doesn't work
汇编不会跳到NegativeNumber过程中,虽然输入的号码负。
以下是我的实际代码
section .data
str1:db 10,13, 'Enter the number'
str1len equ 19
str2: db 10,13, 'The number is positive'
str2len equ 22
str3 : db 10, 13, 'The number is negative'
str3len equ 22
section .bss
num resw 1
cbuff resw 1
global _start
section .text
_start:
%macro sys_read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro sys_write 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
call GetNumber
GetNumber:
sys_write str1, str1len
sys_read cbuff , 1
mov ax , [cbuff]
cmp ax , 0h
jl NumberNegative
sys_write str2, str2len
ret
NumberNegative:
sys_write str3, str3len
ret
是否有任何其他的方法来确定给定的数字,而无需使用标志正面还是负面的? 我在做错事吗? 顺便说一句,我在Linux ubuntu上使用NASM。
什么是'as'?你的意思是'斧头'?另外,如果你正在处理16位数字,你应该检查位15,而不是位7(或者只是'测试ax,ax','js Negative')。 – Michael
是的。抱歉。它的斧头。我现在纠正了问题。好的,你能告诉我如何检查15位?谢谢 – MCCshreyas
2^15 = 0x8000,使用。 –