There is an example, I will cite below. In general, understood, understood with memory, in general, everything is clear, but it is not clear how to do the task - so that the program processes an array of arbitrary length. There is such code:

.DSEG .ORG 0x60 arr: .BYTE 10 .CSEG ;сСгмСнт ΠΊΠΎΠ΄Π° rjmp Reset ;Π²Π΅ΠΊΡ‚ΠΎΡ€ прСрывания, Π²Ρ‹Π·Ρ‹Π²Π°Π΅ΠΌΠΎΠ³ΠΎ ΠΏΠΎ сбросу ΠΌΠΈΠΊΡ€ΠΎΠΊΠΎΠ½Ρ‚Ρ€ΠΎΠ»Π»Π΅Ρ€Π° Reset: ;Π½Π°Ρ‡Π°Π»ΠΎ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ ldi XH,HIGH(arr) ;ΡƒΠΊΠ°Π·Π°Ρ‚Π΅Π»ΡŒ X ΠΏΡ€ΠΎΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠΌ ldi XL,LOW(arr) ;адрСса Π½Π°Ρ‡Π°Π»Π° массива arr ldi YH,HIGH(arr+10) ;ΡƒΠΊΠ°Π·Π°Ρ‚Π΅Π»ΡŒ Y ΠΏΡ€ΠΎΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠΌ ldi YL,LOW(arr+10) ;адрСса ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅Π³ΠΎ Π·Π° послСдним элСмСнтом массива arr ldi r16,5 ;Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠ° Π² счСтчик Ρ†ΠΈΠΊΠ»Π° r16 числа 5 cycle: ld r0,X ;ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π² r0 содСрТимого ячСйки ΠžΠ—Π£, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ X ld r1,-Y ;ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π² r1 содСрТимого ячСйки ΠžΠ—Π£, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ;ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Y с ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΡƒΠΌΠ΅Π½ΡŒΡˆΠ΅Π½ΠΈΠ΅ΠΌ Y Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡ†Ρƒ st Y,r0 ;ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ r0 Π² ячСйку ΠžΠ—Π£, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Y st X+,r1 ;ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ r1 Π² ячСйку ΠžΠ—Π£, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ X ;с ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ ΡƒΠ²Π΅Π»ΠΈΡ‡Π΅Π½ΠΈΠ΅ΠΌ X Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡ†Ρƒ dec r16 ;r16<-(r16-1) cpi r16,0x00 ;сравнСниС r16 с Π½ΡƒΠ»Π΅ΠΌ brne cycle ;ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π΅Π½ΠΈΠ΅ Ρ†ΠΈΠΊΠ»Π°, Ссли Π½Π΅ 0 rjmp PC ;бСсконСчный Ρ†ΠΈΠΊΠ» 

As I understood, on the basis of the condition, I need to make it so that I can put any number in arr: .BYTE **** and it was handled normally. So, somehow, it is necessary for Y to know the end, and then with the counter it will be easier to do this so that Y knows the end of the array?
Or do not dig in the wrong direction and think wrong?

  • one
    And if you just put a label after arr: .BYTE 10 and initialize YH / YL with the address of this label? - alexlz
  • And if it is not 10, but 100, for example? how does y understand that the end is no longer 10? Or I do not understand? - DizzWebS
  • one
    Well .DSEG .ORG 0x60 arr: .BYTE 100 arrend: ... ldi YH, HIGH (arrend); the pointer Y is initialized with the value ldi YL, LOW (arrend); the addresses following the last element of the arr array
  • Thank! And on the counter do not tell? I don’t know yet how to β€œcatch” the number (actually, from .byte), which I need to do, including with a counter. - DizzWebS 5:26
  • one
    Counter (I'm afraid to lie). I hope such expressions in this assembler are valid. ldi r16, (arrend-arr) / 2 In general, if this is not a learning task, then it is better to write in C (at least the gcc port for avr8. For winds it is called winavr) - alexlz

1 answer 1

In order for the program to process an array of arbitrary length, information about the length of the array is needed in any case. It must either be in the form of a separate number in which the length of the array is stored, or in the array itself there must be a sign of its end. For example, the ASCIIZ strings are encoded with the end sign β€” these strings are ordinary arrays of arbitrary length, which at the end of the array always have a zero element.