【8086彙編(實驗)】循環結構

題目一

寫一個完整的8086彙編語言程序:鍵盤輸入10個數據,存入一維數組中(字),並找出數組中最大值顯示在屏幕上。

源碼

;Program:
;Author:Nonoas
;Date:20191106

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

INCLUDE io.h            ; header file for input/output

cr      EQU     0dh     ; carriage return character
Lf      EQU     0ah     ; line feed

.STACK  4096            ; reserve 4096-byte stack

.DATA                   ; reserve storage for data

prompt1 byte ".Enter a number of Array:",0
prompt2 byte cr,lf,"The max number is:",0
number byte 20 dup (?)
maxNum byte 20 dup (?)
nbrArrary WORD 100 dup (?)
count word ?

.CODE                           ; start of main program code
_start:
    mov ecx,10
    mov count,1
    mov dx,count
    lea ebx,nbrArrary
forCount:
    itoa count,dx
    output count
    output prompt1
    input number,20
    atoi number
    mov [ebx],ax
    add dx,1
    add ebx,2
loop forCount

    mov ecx,9
    lea ebx,nbrArrary
    mov ax,[ebx]
forCount1:
    add ebx,2
    cmp [ebx],ax
    jb endJudge
    mov ax,[ebx]
endJudge:
    loop forCount1

    output prompt2
    itoa maxNum,ax
    output maxNum


        INVOKE  ExitProcess, 0  ; exit with return code 0
PUBLIC _start                   ; make entry point public

END                             ; end of source code

題目二

寫一個完整的8086彙編語言程序:鍵盤輸入10個數據,存入一維數組中(雙字),並找出數組中最小的偶數顯示在屏幕上,若沒有偶數則顯示“沒有偶數!”。

源碼

;Program:
;Author:Nonoas
;Date:20191106

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

INCLUDE io.h            ; header file for input/output

cr      EQU     0dh     ; carriage return character
Lf      EQU     0ah     ; line feed

.STACK  4096            ; reserve 4096-byte stack

.DATA                   ; reserve storage for data
prompt1 byte ".Enter a number of Array:",0
prompt2 byte cr,lf,"The min even number is:",0
prompt3 byte cr,lf,"There is no even number",0
number byte 20 dup (?)
minNum byte 20 dup (?)
nbrArrary DWORD 100 dup (?)
count DWORD ?

.CODE                           ; start of main program code
_start:
    mov ecx,10
    mov count,1
    mov edx,count
    lea ebx,nbrArrary
forCount:
    dtoa count,edx
    output count
    output prompt1
    input number,20
    atod number
    mov [ebx],eax
    add edx,1
    add ebx,4
loop forCount

    mov ecx,10          ;judge have even
    lea ebx,nbrArrary
FIND:
    mov al,[ebx]
    test al,01H        ;if isodd, jump to next
    jnz NEXT
    mov edx,[ebx]       ;if iseven, save it
    jmp FINDEND
NEXT:
    add ebx,4
loop FIND

    mov edx,0FFFFH
    jmp EXIT
FINDEND:           ;if find a even , jump here

    mov ecx,10           ;find the min even
    lea ebx,nbrArrary
FIND2:
    mov al,[ebx]
    test al,01H
    jnz NEXT2        ;if is odd, jump to next
    cmp edx,[ebx]
    jb NEXT2
    mov edx,[ebx]
NEXT2:
    add ebx,4
    loop FIND2

    output prompt2
    dtoa minNum,edx
    output minNum
    jmp endall

EXIT:
    output prompt3
    jmp endall

endall:

        INVOKE  ExitProcess, 0  ; exit with return code 0
PUBLIC _start                   ; make entry point public

END                             ; end of source code

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章