error: unable to find valid values for all labels after 1003 passes; stalled for 1001, giving up

error: unable to find valid values for all labels after 1003 passes; stalled for 1001, giving up

我是 NASM 编码新手,正在尝试字符串操作但一直收到错误消息:

unable to find valid values for all labels after 1003 passes; stalled for 1001, giving up.

尝试了网上的所有方法,但找不到任何解决方案。

%macro scall 4          
    mov rax,%1
    mov rdi,%2
    mov rsi,%3
    mov rdx,%4
    syscall         ;call the kernel           
%endmacro

%macro quit 0
    mov rax,60 
    mov rdi,0 
    syscall

%endmacro

section .data
    m1 db 10d,13d,"Enter the String",10d
    l1 equ $-m1
    m2 db 10d,13d,"Length of string",10d,13d
    l2 equ $-m2
    m3 db 10d,13d,"Reversed String",10d,13d
    l3 equ $-m3
    m4 db 10d,13d,""
    l4 equ $-m4
    m5 db 10d,13d, "1.Enter the String "
    l5 equ $-l5
    m6 db 10d,13d, "2.Length of String "
    l6 equ $-l6
    m7 db 10d,13d, "3.Reverse of String"
    l7 equ $-l7
    m8 db 10d,13d, "4.exit"
    l8 equ $-l8
        
section .bss
    string resb 50
    string2 resb 50
    length resb 16
    answer resb 16
    choice resb 8
        
section .text
    global _start
_start:
scall 1,1,m4,l4

menu: 
    scall 1,1,m5,l5
    scall 1,1,m6,l6
    scall 1,1,m7,l7
    scall 1,1,m8,l8
    scall 0,0,choice,2
    
case1:
cmp choice,31h
je enterstring

case2:

cmp choice,32h
je len

case3:

cmp choice,33h
je rev

case4:

cmp choice,34h
je exit
    
    scall 1,1,m4,l4
    
enterstring:
    scall 1,1,m4,l4
    scall 1,1,m1,l1
    scall 0,0,string,50
    jmp menu
    
len:
    mov [length],rax

    scall 1,1,m2,l2
    mov rax,[length]
    call display            ;call  display procedure
    jmp menu
    
rev:
    scall 1,1,m3,l3
    call reverse
    jmp menu

exit:
quit

;*******DISPLAY LENGTH ***********       
display:                        ;hex to ascii-hex
    mov rbp,answer
    mov rcx,2

loop1:
    rol al,04
    mov dl,al 
    and dl,0Fh 
    cmp dl,09h
    jbe loop2
    add dl,07h 
loop2:
    add dl,30h 
    mov [rbp],rdx 
    inc rbp
    dec rcx
    jnz loop1 
scall 1,1,answer,6 
ret

;****** DISPLAY REVERSE STRING*******
reverse:
    mov rsi,string     ; point rsi to first byte of original srting
    mov rdi,string2    ; point rdi to first byte of reversed string 
    mov rcx,[length]   ; counter 
    add rsi,rcx        ; point rsi to next byte after original string 
    dec rsi            ; now rsi points to last byte
next:
    mov rax,[rsi]       ;move character to al 
    mov [rdi],rax       ;Copy character to string2
    dec rsi
    inc rdi
    loop next
scall 1,1,string2,50
ret

这是我每次在这段代码中遇到的 NASM 错误:

error: Can't find valid values for all labels after 1000 passes, giving up.
error: Possible causes: recursive EQUs, macro abuse.

l5 equ $-l5 应该是 l5 equ $-m5,对于其他从位置减去长度而不是减去两个位置的长度也类似。

另外,这个定义本身就是递归的 (l5 = stuff - itself),所以这是个问题。


这就是您收到 错误的原因;一旦修复,NASM 就可以找到其他错误并告诉您这些错误,但是这些错误都有行号,因此您可以找到问题出在哪一行。 (例如,尝试 cmp choice, 31h,其中 choice 是符号名称,即地址。cmp 不适用于两个立即数,无论如何这不是你想要的。使用 default relcmp byte [choice], 31h,可能。)