Basic for-loop in 68k assembly?


I'm attempting to write a program which requires the use of a for-loop, among other things. I am having a terrible time trying to find examples of basic code such as this on other websites.

If someone could please provide me with a simple for loop, or even the instructions I should be looking at I would be greatful. And please, if you know of a good resource for 68k beginner tutorials, comment below!


See here for an answer to your query (3rd result in google search '68000 assembly')


add answer from link

The 68000 has the rare (unique?) characteristic of having separate address and data registers. There are eight data registers, D0-D7, and eight address registers, A0-A7. A7 is also the stack pointer, SP. This means that 68000 assembly language tends to be easier to follow because you can easily tell which registers hold data and which hold addresses. For example, this is 68000 assembly to compute the sum of an array of words:

    moveq #0, d0
    moveq #0, d1
    moveq #5, d2
    move.w (a0)+, d0
    add.l d0, d1
    dbra d2, loop


As cited in EASy68K help, the syntax for a for loop in 68K is as follows:

FOR[.size] op1 = op2 TO op3  [BY op4]  DO[.extent]


FOR[.size] op1 = op2 DOWNTO op3  [BY op4]  DO[.extent]

in other words:

for.size counter_location = starting_condition to ending_condition step_size
   operations to be executed each loop
end of for loop

The step_size and .size are both optional.

An example in practice.
The following code assumes the following variable uppercase dc.b 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',0

lea    uppercase, a1    ; points a1 at the start of the uppercase variable
lea    $002000, a2      ; points a2 at the start of the destination address

for d1 = #1 to #26 do.s
    move.b  (a1)+, (a2)+

; Memory locations $002000 - $002019 now contain ABCDEFGHIJKLMNOPQRSTUVYWXYZ

This loop moves 26 bytes from the address pointed to by a1, to the address pointed to by a2. The counter will be stored in d1. The loop will start at 1 (#1 indicates a 'raw number' in decimal form), increase each time, and end at 26. The do.s at the end of the first line deals with the size of the forward branch to use. It is optional as well, but throws a warning in EASy68K. Hence, the below for-loop will also work if you don't need to set the branch condition.

for d1 = #1 to #26
    move.b  (a1)+, (a2)+

Concerning a tutorial, I recommend . It doesn't deal with some of the more advanced commands and topics, but it offers a good understanding of what is happening on the basic/intermediate level.

This video can help you solving your question :)
By: admin