It is currently Sat May 30, 2020 5:34 am

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Programming code
PostPosted: Fri Dec 13, 2019 10:40 am 

Joined: Fri Dec 13, 2019 8:57 am
Posts: 2
Dear Mr Kelly, or any other kindness soul who whants to help.

I am working with this program to try to understand how the machine works, I am used to high level computational language so this is very confusing. I think I have read tons and tons of information but I think I am not progressing at all. So any help would be appreciated

Pd: Sorry if some words are "spanglish" but my english is a little bit rusty =P

So lets begin,

I have to make a program which the user enters a string and the program make a count about how many characters, numbers and spaces are in the string.

I made this pseudocode to figure it out the logic of the exercise,

phrase: string
digit, space, character, i: int
read phrase
space = 0
digit = 0
For i = 0 to string (i) = "/0", i = i + 1
Switch string (i)
string (i) = ""
space = space + 1
string (i) = 1
digit = digit + 1
string (i) = 2
digit = digit + 1
string (i) = 3
digit = digit + 1
string (i) = 4
digit = digit + 1
string (i) = 5
digit = digit + 1
string (i) = 6
digit = digit + 1
string (i) = 7
digit = digit + 1
string (i) = 8
digit = digit + 1
string (i) = 9
digit = digit + 1
string (i) = 0
digit = digit + 1

character = i
character = character - space - digit
write character
write space
write digit

Ok, now let's start to write the code, I look for some starting examples and I could wrote this:

    ORG    $1000 *this is where the code is storaged but some times I saw $2000 and $3000 and do not know why
START:                  ; first instruction of program

*This block is to answer the string

    LEA     MESSAGE1,A1  *Charges message in A1
    MOVE.B  #14,D0         *Moves byte data from origin to destiny, so I understand I am moving from memory direction 14 to register (data bus) D0
                                     *I found this is like cout so this is why I'm using it
    TRAP    #15                *This stops the system with priority 15
*This block storage the string
    LEA     BUFFER,A1   * Here I storage the string
    MOVE.B  #2,D0       * Now I read the string, similar to cin>>string, lenght is in D1.W direction
    TRAP    #15            * I don't understand why is always the same stop priority, I read there this trap is the following:

*Display the unsigned number in D1.L converted to number base (2 through 36) contained in D2.B
*at this moment I have searched explanations but is like chinese
*This block shows the message

    LEA     MESSAGE2,A1 *Charges message in A1, using the same direction so I understand I am removing message1 with message2
    MOVE.B  #14,D0     
    TRAP    #15         
*This block shows the string

    LEA     BUFFER,A1   ; Rescue string storage in A1
    MOVE.B  #13,D0      ; Shows the string in a new line, if not is MOVE.B #14,D0
    TRAP    #15

    MOVE.B   #9,D0 *I don't understand this command

    TRAP   #15          ; halt simulator

message1 dc.b 'enter your string: ',0
message2 dc.b 'string you have entered is: ',0

    ds.w    0           * the command ds is to storage bytes so i don't understand why we storage 0 words
buffer  ds.b    80   * this is to storage 80 bytes, I guess is the lenght of the string

    END    START        ; last line of source

So now I have this and I would like to continue, I guess the code I have to use is some kind of this:

LOOP MOVE.L #10,D0 *Loop counter in D0
CMP.B #$ff,D0 *#$ff is a word type (2 bytes) so I have to use CMP.B to compare words in the string so I suppose I have to use this.
ADD.B #1,D0 *increment counter from direction 1 to D0
BNE LOOP * make the loop while D0 <> 0

Looking for another codes It's seems to me that I have to write a lot of things but Im so lost,


 Post subject: Re: Programming code
PostPosted: Sun Dec 15, 2019 11:36 am 
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
You are on the correct path. The program you are attempting to write is complex for someone that does not know Assembly language. I suggest starting with smaller programs first. Look in the EASy68K/Examples folder and online: http://www.easy68k.com/easy68kexamples.htm

Prof. Kelly

 Post subject: Re: Programming code
PostPosted: Fri Feb 21, 2020 9:46 pm 

Joined: Thu Feb 20, 2020 8:02 pm
Posts: 11
I will try to answer some questions...

The ORG directive tells the assembler what is the start address of your program. All labels, DC, DS and other directives will be calculated from that address. For EASy68k it's not so important because you have the full address space available, but on real hardware the operating system would take care of loading your program in memory and adapt all labels, DC, DS etc. (this is called "relocation). Even if you are free to choose the address of your program, you have to make sure that it's allowed by your hardware as it would reserve some areas depending on the amount of RAM you have, and memory zones reserved for interactions with peripherals.

The comment on "MOVE.B #14,D0" is not correct. # means it's an immediate value, not a memory address.

The following is commented as something you don't understand:
MOVE.B #9,D0
TRAP #15

But it's simply a call to a EASy68k function to terminate the program (similar to the SIMHALT directive).

I attached a small program which does what you say, ie counts characters, spaces and digits in a string entered by the user.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 15 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group