【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

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nonoas

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值