【发布时间】:2019-06-05 17:33:33
【问题描述】:
我正在为汇编语言中的字符串排序编写冒泡排序,并且我正在使用 strtok() 来标记字符串。但是,在第一次调用strtok(str," ")之后,我需要传递NULL作为参数,即strtok(NULL," ")
我在 .bss 段中尝试了 NULL equ 0 但这没有任何作用。
[SECTION .data]
[SECTION .bss]
string resb 64
NULL equ 0
[SECTION .text]
extern fscanf
extern stdin
extern strtok
global main
main:
push ebp ; Set up stack frame for debugger
mov ebp,esp
push ebx ; Program must preserve ebp, ebx, esi, & edi
push esi
push edi
push cadena
push frmt
push dword [stdin] ;Read string from stdin
call fscanf
add esp,12 ;clean stack
push delim
push string ;this works
call strtok
add esp,8 ;clean stack
;after this step, the return value in eax points to the first word
push string ;this does not
push NULL
call strtok
add esp,8 ;clean stack
;after this step, eax points to 0x0
pop edi ; Restore saved registers
pop esi
pop ebx
mov esp,ebp ; Destroy stack frame before returning
pop ebp
ret ;return control to linux
我在“大多数实现”中读到过,NULL 指向 0,不管这意味着什么。为什么会有歧义? x86指令集中的NULL相当于什么?
【问题讨论】:
-
记住你推送参数的顺序...
-
NULL 不指向零,它是零,它不指向任何地方。但正如已经指出的那样,问题在于您的论点顺序。
标签: c assembly x86 nasm null-pointer