Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I am new to Nasm coding , was trying string operations but keep receiving the nasm: error: Can’t find valid values for all labels after 1000 passes, giving up.
nasm: error: Possible causes: recursive EQUs, macro abuse.

Tried all methods on internet but couldn’t find any solution.

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

%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 exi

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

exi:
quit

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

loo1:
rol al,04
mov dl,al
and dl,0Fh
cmp dl,09h
jbe loo2
add dl,07h
loo2:
add dl,30h
mov [rbp],dl
inc rbp
dec rcx
jnz loo1
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 al,[rsi] ;move character to al
mov [rdi],al ;Copy character to string2
inc rdi
dec rsi
loop next

scall 1,1,string2,50
ret

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

this is the error i get everytime in this code

>Solution :

l5 equ $-l5 should be l5 equ $-m5, and similarly for others where you’re subtracting lengths from positions instead of subtracting two positions.

Also, that definition alone is itself recursive (l5 = stuff - itself), so that’s a problem.


That’s why you’re getting this error; once fixed then NASM is able to get to other errors and tell you about them, but those have line numbers so you can find which line is the problem. (e.g. an attempt to cmp choice, 31h, where choice is a symbol name, i.e. address. cmp doesn’t work with two immediates, and that’s not what you want anyway. Use default rel and cmp byte [choice], 31h, probably.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading