Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 使用程序集8086中的堆栈查找数组中的数字_Arrays_Assembly_X86_X86 16 - Fatal编程技术网

Arrays 使用程序集8086中的堆栈查找数组中的数字

Arrays 使用程序集8086中的堆栈查找数组中的数字,arrays,assembly,x86,x86-16,Arrays,Assembly,X86,X86 16,我有一个任务,在汇编语言中编写程序,它接受堆栈的3个参数,并在数组中搜索n值 以下是完整的作业说明: 必须编写一个过程,该过程在 堆栈:字数组地址、数组中的对象数和 数字(我们在这里用n表示)。该过程将在中查找n 数组并在ax寄存器中返回第一个 数组中值等于n的元素。Ax寄存器。如果值 不在数组中,返回-1。在数据段中,两个单词集 必须使用不同的值定义不同的长度。你必须 编写一个主过程,为每个 两个配置的阵列,具有两个不同的搜索值。搜寻 价值观​​将出现在数据段的另一个设置中。主要 过程打印值所

我有一个任务,在汇编语言中编写程序,它接受堆栈的3个参数,并在数组中搜索n值

以下是完整的作业说明:

必须编写一个过程,该过程在 堆栈:字数组地址、数组中的对象数和 数字(我们在这里用n表示)。该过程将在中查找n 数组并在ax寄存器中返回第一个 数组中值等于n的元素。Ax寄存器。如果值 不在数组中,返回-1。在数据段中,两个单词集 必须使用不同的值定义不同的长度。你必须 编写一个主过程,为每个 两个配置的阵列,具有两个不同的搜索值。搜寻 价值观​​将出现在数据段的另一个设置中。主要 过程打印值所在的地址,如果需要,则打印注释 没有找到它。提醒:将单词布局设置为4:arr1 dw 300、50、, 15,48

我需要关于如何启动代码的帮助?如何将参数发送到堆栈? 提前感谢您的帮助

编辑这是我现在的代码:

.STACK  64
.DATA 
arr db 9 dup ?
arr1      dw  1,2,3,4,5   
arr1size  dw  5         
newline db  0AH,0DH,'$' ; newline 
arr2        dw  4,5,6,7,10,10 
arr2size    dw  6        
resu      dw  ?  ; result var
errmsg  db  "of - voer flow"
n dw  0

sendToStack proc
    push bp
    mov bp, sp
    sub sp, 24
    lea dx, arr1
    push dx



    pop dx
    pop bp
    end proc
start:
    mov ax, @data
    mov ds, ax
    call sendToStack

end

继续的建议?

以下是我在Linux上为32位
x86
体系结构开发的代码,它可以在数组中查找数字。代码可能会帮助您入门,但是没有使用
堆栈
,因此堆栈版本仍然是您的家庭作业。我使用
gdb
debugger测试了代码,以逐步完成指令并检查寄存器值,据我所检查,代码按预期工作

我们有以下
makefile
,因此在linux终端上只需键入
make
,即可编译并链接
asmtut.s
文件中的汇编代码:

asmtut: asmtut.o
        ld -o asmtut asmtut.o
asmtut.o: asmtut.s
        nasm -f elf -o asmtut.o asmtut.s
clean:
        rm *.o asmtut
asmtut.s
内的装配代码为:

section .data

array dw 18,99,22,72,40,55,110,23       ; array to be searched

length dd 8     ; array length; note array length can be 32-bit

number dw 40    ; number we search for, i.e. wanted number
;number dw 88   ; this number will NOT be found: to check the not_found fork of the program

index dd 0      ; index of found number ; will be -1 if not found; note index is 32-bit

section .text

global _start
_start:

    xor edi, edi ; set edi=0x00 ; stores current array element index; use 0-based indexing
    xor ax, ax ; set ax=0x00 ; stores current array element
    xor ebx, ebx        ; ebx is used as an intermediary to store 32-bit index

    jmp loop   ; start the search loop

loop:
    mov ax, [array+edi*2]       ; move first array element to ax; note a word is 16bits=2bytes
    cmp ax, [number]            ; compare array element with wanted number
    je found                    ; if equal, wanted value is found: jump to "found" address
    inc edi                     ; increment element index
    cmp edi, [length]           ; see if the element was the last element:
    je not_found                ; if so, the wanted number if not found, jump to "not_found"
    jmp loop                    ; repeat the loop

found:
    mov ebx, edi                ; wanted number is found: use "ebx" as an intermediary to store index
    mov [index], bx             ; store index to memory location for index
    jmp end

not_found:
    mov ebx, -1                 ; wanted number is NOT found: use "ebx" as an intermediary to store -1
    mov [index], ebx            ; move -1 to the memory location for index
    jmp end

end:
    mov bx, 0                   ; move interrupt argument to bx
    mov ax, 1                   ; move "1" to ax which means "exit" interrupt
    int 0x80                    ; interrupt: exit

“如何将参数发送到堆栈?
PUSH
你能给我一个我应该如何做的例子吗?不,你必须自己做作业。堆栈溢出不是一种代码编写服务。在获得作业之前,你应该了解完成此作业所需的说明。或许可以回去看看你的教科书/课堂讲稿/谷歌。在你已经编写了一些代码之后,这个网站工作得更好。然后你可以问一些具体的问题,我们可以帮助你改进它。在“8086堆栈框架”或“8086堆栈传递参数”上进行谷歌搜索“你会发现很多例子和解释来帮助你入门。虽然谷歌搜索可能/应该会有帮助,但是有很多关于如何创建和运行8086代码的变体,你的讲座可能会有特定的目标平台/变体,所以你应该先从课程材料开始,以确保你在搜索正确的例子。