Multidimensional arrays in assembly language

Hello everyone. Can any plz tell me how to handle 2d arrays in assembler 8086. I am starting programming in assembler. Thanks

+3
source share
2 answers

Madhur's link pretty much covers it, have you read this?

if you already understand a 2d array at the C programming level, for example, assembler is the next logical step.

8- , , z [1] [2] , , , C- z , , 13 , so & z + (13 * 1) +2 = & z + 15;

, x86 ( , ).

;brute force
ldr r0,=z ;load address of z into r0
mov r1,#13
mul r1,#1 ;make this a register or load from a memory location
mov r2,#2 ;make this a register or load from a memory location
add r0,r1
add r0,r2
ldrb r1,[r0] ;read the byte
strb r3,[r0] ;write the byte

;if your instruction set allows register offset
ldr r0,=z ;load address of z into r0
mov r1,#13
mul r1,#1
mov r2,#2
add r1,r2
ldrb r4,[r0,r1] ;read the byte
strb r3,[r0,r1] ;write the byte

;or immediate offset and offset is hardcoded
ldr r0,=z ;load address of z into r0
mov r1,#13
mul r1,#1
add r0,r1
ldrb r4,[r1,#2] ;read the byte
strb r3,[r1,#2] ;write the byte

C

unsigned char x[4][16];
unsigned char z[4][16];
unsigned int ra,rb;

for(ra=0;ra<4;ra++)
{
  for(rb=0;rb<16;rb++)
  { 
      x[ra][rb]=z[ra][rb];
  }
}

.

ldr r0,=x
ldr r1,=z
mov r2,#0 ;ra
outer:
  mov r3,#0 ;rb
  inner:
    mov r4,r2 lsl #2 ;16 bytes wide
    add r4,r3
    ldrb r5,[r1,r4]
    strb r5,[r0,r4]
    add r3,r3,#1
    cmp r3,#16
    bne inner
  add r2,r2,#1
  cmp r2,#4
  bne outer

, - + ( ) + ( ). , , , , , , , / # 2 , , 2. .., , , , , , , , , .

, [r0, r1], , , , . (* ptr ++), , , [r0], # 16 r0, r0 16 r0, ... , x86 , , .

, x86, , , , , , , ( , x86 ) .

+6
;This code grabs data bits from accumulator and outputs it to the carry
Main:
clr C
mov A, #00101010b; 
call array; 
jmp Main; 
array:
subb A, #80H; mov can work here if you did not clr C
cpl A; check for proper array location
mov B, #8; set division factor
DIV AB; bit offset contained in B; 
mov R6,B;
subb A, #30H; this bit will allow you to mov around the chosen register
cpl A;   
mov R7, A; 
mov A, @R7; this is the array position
inc R6; 
loop: 
rlc A; this takes the array bit to the carry for easy access
djnz R6, loop; 
-1

Source: https://habr.com/ru/post/1782239/


All Articles