微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

数组操作 - 汇编程序

如何解决数组操作 - 汇编程序

我需要编写一个汇编语言程序来处理最多 20 个字节的数组。该程序将显示直接输入的数组,并以相反的顺序显示(反之亦然)。真正缺少什么?

例如a b c d e f g h i j 0 1 2 3 4 5 6 7 8 9(直)

程序从控制台接受数据并直接显示(无需逆向)

我真的需要做什么才能显示输入的字符串?

enter image description here

在控制台输入后显示的字符需要改变什么?

链.asm

; The program demonstrates the use of the 10th interrupt function 21h
; to load a string directly into pao
;author: xyz
.286
.model small
.data
Inscription db "Enter the inscription",13,10,'$'
bufor db 20,20 dup ('$')
.code
start:
       ;przyg. segmentowej cz. adresu
       mov ax,seg _data
       mov ds,ax

       ;przyg. offsetowej cz. adresu
       mov dx,offset napis

       ;display the inscription
       mov ah,09h
       int 21h

       ;load chain
       mov dx,offset bufor
       mov ah,0ah
       int 21h

       mov ax,4c00h
       int 21h
end start

循环

;The program demonstrates the use of the 2nd interrupt function 21h
;to read single characters to pao through the al register
;author: xyz
.286
.model small
.data
inscription db "Enter the inscription",offset napis
       mov di,dx
       ;wyswietlenie znakow
       mov cx,10h
       mov ah,02h
print:
       mov dl,ds:[di]
       int 21h
       inc di
       dec cx
print Now

       ;wczytanie znakow
       mov dx,offset bufor
       mov di,dx
       mov ah,01h
enter:

       int 21h
       mov ds:[di],al
       inc di
       cmp al,13 ;czy enter?
already type

       mov ax,4c00h
       int 21h
end start

解决方法

看看

;przyg. offsetowej cz. adresu
mov dx,offset napis

String napis 未在程序中定义。要么使用 mov dx,offset Inscription
或在您的代码中添加类似 napis EQU Inscription 的内容。

您正在使用 BUFFERED INPUT 填充键盘中的 bufor。此函数使用 bufor 的前两个字节作为标头。第二个字节包含读取的字符数,这些实际字符从偏移量 bufor+2 开始。在程序开始时,bufor 包含(十六进制):
14 00 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
当您输入时,例如,1 2 3 4 5 Enter,函数在 bufor 中返回:
14 05 31 32 33 34 35 0D 24 24 24 24 24 24 24 24 24 24 24 24 24 24

为了显示缓冲区内容,您可以使用 Int 21/AH=09h 一次显示整个字符串

      ;load chain
      mov dx,offset bufor
      mov ah,0ah
      int 21h
      ; Print the contents of bufor,which is $-terminated.    ​
      ​MOV DX,offset bufor+2 ; Let DS:DX point to the first entered char.
      ​MOV AH,9              ; WRITE STRING TO STANDARD OUTPUT
   ​   INT 21h               ; Invoke DOS function.

迭代字符,一个接一个地循环:

     ​    ;load chain
         ​mov dx,offset bufor
     ​    mov ah,0ah
         ​int 21h
         ; Print characters in bufor.
​         MOV SI,offset bufor+2  ;Let DS:SI point to the first entered char.
         MOV CL,byte [SI-1]     ; Let CL=number of entered chars.
         MOV AH,2               ; Prepare for INT21h/AH=2.
    Next:MOV DL,[SI]            ; Load character to DL.
         INT 21h                ; WRITE CHARACTER TO STANDARD OUTPUT.
         INC SI                 ; Prepare to the next character.
         DEC CL                 ; Count remaining characters.
         JNZ Next               
       

当您想以相反的顺序打印时,让 DS:SI 指向最后输入的字符并继续递减 SI 而不是 INC SI

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。