【汇编 题目】30,31 已知数组A包含20个互不相等的字型整数,数组B包含30个互不相等的字型整数,试编制一程序把既在A中又在B中出现的数存放于数组C中。

重点

主要注意这几点:

  1. 十六进制输出方法,要完全掌握
  2. 注意mov es,ax
  3. 注意要利用指令cld,将循环方向清零

代码

;已知数组A包含20个互不相等的字型整数,
;数组B包含30个互不相等的字型整数,
;试编制一程序把既在A中又在B中出现的数存放于数组C中。

DATAS SEGMENT
    ;此处输入数据段代码  
    buf1 DW 123BH,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
    buf2 DW 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
    buf3 DW 20 DUP(?)
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
main proc far
    mov ax,DATAS
    mov ds,ax
    mov es,ax
    
    mov si,0
    mov di,0
loop_begin:
    cld                 ;注意这里,将循环方向清零
    mov ax, buf1[si]
    cmp si,40
    je print0

    add si,2
    push di
    mov cx,30
    lea di,buf2
    repnz scasw
    pop di
    jne loop_begin
    mov buf3[di],ax
    add di,2
    jmp loop_begin

print0:
    mov si,0
    mov di,0
    mov cx,20
print:
    mov bx,buf3[si]
    push cx
    call print_proc
    pop cx
    mov dl,0ah
    mov ah,02h
    int 21h
    add si,2
    loop print 

    mov ah,4ch
    int 21h

main endp

print_proc proc near
    mov dx,bx
    mov cl,4
    shr dh,cl
    add dh,30h
    cmp dh,39h
    jle first
    add dh,07h
first:
    mov dl,dh
    mov ah,02h
    int 21h

    mov dh,bh
    and dh,0fh
    add dh,30h
    cmp dh,39h
    jle second
    add dh,07h
second:
    mov dl,dh
    mov ah,02h
    int 21h

    mov dl,bl
    shr dl,cl
    add dl,30h
    cmp dl,39h
    jle third
    add dl,07h
third:
    mov ah,02h
    int 21h

    mov dl,bl
    and dl,0fh
    add dl,30h
    cmp dl,39h
    jle forth
    add dl,07h
forth:
    mov ah,02h
    int 21h

    ret
print_proc endp
CODES ENDS
    END main

猜你喜欢

转载自blog.csdn.net/qq_43874964/article/details/109732206