2017-06-14 5 views
-2

スタックに3つのパラメーターを受け取り、配列のn値を検索するプログラムをAssembly langに書き込むことができます。ワードアレイアドレス、配列内のオブジェクトの数、および 数:アセンブリーでスタックを使用して配列番号を検索する8086

は手順を書く スタック上の3つのパラメータを受け入れることを書かなければなりません。ここに

は、割り当てを説明いっぱいです(ここではnで示す)。この手順では、配列 のnを検索し、その値がnに等しい配列内の最初の 要素のアドレスをaxレジスタに返します。 Axレジスタ。値 が配列にない場合は、-1を返します。データセグメントでは、異なる長さの の2つの単語セットを異なる値で定義する必要があります。 2つの異なる検索値を使用して、2つの構成済みアレイの アレイごとにfindプロシージャを実行するメインプロシージャを記述する必要があります。検索 の値は、データセグメントの別の設定に表示されます。メインの プロシージャは、値が格納されているアドレスまたは が見つからない場合はノートを出力します。注意: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 

の提案ですか?

+1

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内のアセンブリコードです"スタックにパラメータを送る方法?*' PUSH' –

+0

あなたは私にそれをどうすればいいかの例を教えていただけますか? –

+1

いいえ、自分の宿題をしなければなりません。 verflowはコード作成サービスではありません。あなたは、この課題を行う前に*課題を取得するのに必要な手順を学んだはずです。おそらく戻ってあなたの教科書/講義ノート/ Googleを見直してください。このサイトは、すでにいくつかのコードを書いた後にうまく機能します。その後、*具体的な*質問をすることができます。 –

答えて

0

これは、32ビットのx86アーキテクチャー用にLinuxで開発したコードで、配列内の数字を検出します。このコードは、開始に役立つかもしれませんが、stackを使用していないため、スタックバージョンは宿題のままです。 gdbデバッガを使ってコードをテストし、命令をステップ実行し、レジスタの値を確認しました。チェックしたところで、コードは期待通りに機能します。

のLinux端末上だけmakeを入力してasmtut.sファイル内のアセンブリコードがコンパイルとリンクされているように、我々は、以下のmakefileを持っている:*

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 
関連する問題