EASy68K
http://easy68k.com/EASy68Kforum/

How constants work
http://easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1541
Page 1 of 1

Author:  nych [ Wed Mar 09, 2016 11:08 pm ]
Post subject:  How constants work

Was wondering how am I able to assign a certain constant I declared a integer.
For example I have 10 constants and I want to list them from 1-10. I am trying to write a code where I type a integer then prints out the constant that is dedicated to that.

Author:  Obeisance [ Sat Mar 12, 2016 12:24 am ]
Post subject:  Re: How constants work

Let me preface this by saying that I have not tried this. I've only been reading a disassembly, so I am not perfectly sure how conventional notation is used, nor have I practiced what I will say. Based on my understanding, there are many ways to load up a constant value to then be displayed. I believe that some of the Trap (TRAP #15 ;??) exceptions in EASy68k may be linked to print functions as well, but I cannot be sure. You could try copying some of the example code to get printing and inputs to work.

As far as linking an index number to a stored constant, perhaps you could use a move command to store a constant in memory (choose a memory address which is higher than your code or which does not coincide with your instruction addresses).

Code:
MOVEA.L ($HexAddress).L,A2
MOVEA.L ($4,A2),A3   ;a displacement of 4 (one long word) beyond HexAddress defines the address in A3
MOVE.L #constantNumber,A3


In this example, constantNumber is a decimal that is your storable constant and HexAddress is a hexadecimal memory address (something between 0x400 and 0xFFFFFF).

Then, in order to load up the constant based on input, move the input value (this is your number, 1-10) into a register, say D0, and use another effective addressing mode (indexed indirect) to load the stored constant onto a different register which can be passed to the printing function (by calling the TRAP exception command?).

Code:
MOVEA.L ($HexAddress).L,A2  ;puts the base address where your constants are stored into a register
       ;assuming that D0 is a long word index value which specifies the
       ;displacement from $HexAddress (in long words, hence the "*4") where your constant is stored
MOVE.L ($0,A2,D0.L*4),D2   ;moves your stored value onto D2


Again, I am only answering in spite of the cricket noise on this forum. I have not practiced this, but would like to participate in conversation. So when my advice inevitably fails, post again and let me know what you're thinking.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/