How to clear an array in assembly language?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to clear an array in assembly language?

Jump to solution
6,216 Views
mnemonic
Contributor III

Hello experts!

 

Can anyone tell me please, how to clear an array in asm?

 

ARRAY: DS.B 64

VAR1:    DS.B 1

VAR2:    DS.B 2

 

clr VAR1    ;clear VAR1

clr VAR2    ;clear VAR2, deletes only the first address

clr VAR2+1 ;clear VAR2, deletes the 2nd address too

clr ARRAY   ;deletes only the first address but how can I clear the rest of the reserved space

 

 

would be very nice if someone could help me!

 

best regards

 

Ingo Kauf 

Labels (1)
0 Kudos
1 Solution
3,077 Views
tonyp
Senior Contributor II

First of all, try to use symbols rather than the actual numbers, at all times.  It makes the code more readable and more easily updateable.  Regarding your question, something like this:

 

ARRAY_SIZE equ 64

 

Array rmb ARRAY_SIZE

 ...

 ldhx #Array

Loop

 clr ,x

 aix #1

 cphx #Array+ARRAY_SIZE

 blo Loop

 ...

 

Message Edited by tonyp on 2009-08-14 11:30 AM

View solution in original post

0 Kudos
3 Replies
3,078 Views
tonyp
Senior Contributor II

First of all, try to use symbols rather than the actual numbers, at all times.  It makes the code more readable and more easily updateable.  Regarding your question, something like this:

 

ARRAY_SIZE equ 64

 

Array rmb ARRAY_SIZE

 ...

 ldhx #Array

Loop

 clr ,x

 aix #1

 cphx #Array+ARRAY_SIZE

 blo Loop

 ...

 

Message Edited by tonyp on 2009-08-14 11:30 AM
0 Kudos
3,077 Views
bigmac
Specialist III

Hello Ingo,

 

There is generally more than one method of solving a particular problem.  For example, provided the array size is less than 256 bytes, the following method may provide a simpler solution.

 

ARRAY_SIZE equ 64

array: rmb ARRAY_SIZE

...

 

   ldhx #ARRAY_SIZE

   clra
LOOP:

   sta  array-1,x

   dbnzx LOOP

 

Regards,

Mac

 

0 Kudos
3,077 Views
mnemonic
Contributor III

Thank you very much! This was very fast!

 

I will work on this at evening.

 

best regards,

 

Ingo Kauf

0 Kudos