【问题标题】:Operations on arrays - Assembler数组操作 - 汇编器
【发布时间】:2021-06-03 21:32:27
【问题描述】:

我需要编写一个汇编语言程序来处理一个最大 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,0,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",13,10,'$'
bufor db 20,0,20 dup ('$')
.code
start:
       ;przyg. segmentowej cz. adresu
       mov ax, seg _data
       mov ds, ax

       ;przyg. offsetowej cz. adresu
       mov dx, 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

【问题讨论】:

  • 这不是 [gnu-assembler] .intel_syntax noprefix。不要使用不适用的标签。对我来说,它看起来像 MASM 或 TASM 语法。
  • 你知道这段代码是做什么的吗?
  • 我有点知道鳕鱼在做什么,但我不知道如何才能得到能显示所写内容的东西,即功能 9 和 10 合二为一
  • 我想说我不知道​​如何连接这两个函数,因为我希望我输入的脚本字符串再次显示

标签: assembly x86-16 masm


【解决方案1】:

看看

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

字符串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 this:
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

【讨论】:

  • 中断21h函数0Ah的头部实际上只有两个字节。
  • @ecm 我不得不在调试器中尝试它,是的,你是对的。 Int 21/AH=0Ah 的文档非常具有误导性:-(
  • 我只是在看 ``` ;przyg。 offsetowej cz. adresu mov dx, offset napis ``` "程序中没有定义字符串 napis ....." 我应该在我看的地方添加吗?所以```;przyg。 offsetowej cz. adresu mov dx, offset napis mov dx, offset Inscription ``` - 我编译时出错 下一部分对我来说很难理解,但我知道你对这个编号的意思,但它有什么作用? “为了显示缓冲区内容,您可以使用....”这应该是什么意思 int 21 ah = 09h - 我知道这是一个函数,但我必须在哪里输入它
  • @KamilSosnowski 您必须将函数 Int21h/AH=9 准确地插入源中的那个位置,您希望该函数打印字符串 DS:DX。也许您最好从一些 Hello,world! 示例开始,以熟悉您正在使用的工具链。
猜你喜欢
  • 2012-11-12
  • 1970-01-01
  • 2011-08-06
  • 2017-01-08
  • 1970-01-01
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多