Kamil Sosnowski
Kamil Sosnowski

Reputation: 11

Operations on arrays - Assembler

I need to write an assembly language program that processes an array of max 20 bytes. The program's to display the array as it's entered directly and in the opposite order (vice versa). What is really missing?

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

the program accepts data from the console and displays it directly (without reversing)

What do I really have to do to make the entered string display ?

enter image description here

What needs to be changed for the characters to be displayed after typing in the console ?

Chain.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

Loop

;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

Upvotes: 0

Views: 207

Answers (1)

vitsoft
vitsoft

Reputation: 5805

Look at

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

String napis is not defined in the program. Either use mov dx, offset Inscription
or add something like napis EQU Inscription to your code.

You are using BUFFERED INPUT to fill the bufor from keyboard. This function uses first two bytes of the bufor as a header. Second byte contains the number of characters read, and those actual characters begin at offset bufor+2. At the start of program, bufor contains (in hexadecimal):
14 00 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
When you enter, say, 1 2 3 4 5 Enter, function returns in bufor this:
14 05 31 32 33 34 35 0D 24 24 24 24 24 24 24 24 24 24 24 24 24 24

In order to display buffer contents you could use Int 21/AH=09h to display the entire string at once:

      ;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.

or iterate characters, one after another in a loop:

     ​    ;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               
       

When you want to print in reversed order, let DS:SI point to the last entered char and keep decrementing SI instead of INC SI.

Upvotes: 1

Related Questions