EASy68K  
It is currently Wed Oct 17, 2018 1:28 am

All times are UTC




Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Sun Apr 12, 2009 12:15 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
How do i store values in an array ?? Is there any tutorial or notes u recommend i could read.


How do i go about converting an entry to uppercase. Thank u


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 12, 2009 3:42 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
There are different methods for accessing the data in arrays. I would recommend finding a good reference book on 68000 programming. A Google search also revealed an online reference.

Here is an example program that reads 10 numbers from the keyboard, stores them in an array, then displays the number from the array.

Code:
*-----------------------------------------------------------
* Program    : Array programming
* Written by : Chuck Kelly
* Date       : April, 2009
* Description: Get 10 numbers from keyboard, store them in
*              an array then display them from the array.
*-----------------------------------------------------------
    ORG $1000
SIZE    equ     4   ; data size (4 bytes for long word)

START:              ; first instruction of program

    * read 10 numbers from keyboard and store in array
    lea array1,A0           ; pointer to array
   
    for D2 = #0 to #9*SIZE by #SIZE do.s  ; loop 10 times
        lea     prompt,A1   ; pointer to string
        move.b  #13,D0      ; display prompt
        trap    #15
       
        move.b  #4,D0       ; read number from keyboard into D1.L
        trap    #15
               
        move.l  D1,(A0,D2)  ; store number to array at index D2
    endf
   
    lea     result,A1       ; pointer to string
    move.b  #13,D0          ; display result
    trap    #15
   
    * display numbers from array
    for D2 = #0 to #9*SIZE by #SIZE do.s  ; loop 10 times
        move.l  (A0,D2),D1  ; get number from array at index D0
        move.b  #3,D0       ; display number in D1.L
        trap    #15
       
        lea     crlf,A1     ; pointer to string
        move.b  #14,D0      ; display cr lf
        trap    #15
    endf
       
    MOVE.B  #9,D0
    TRAP    #15     ; halt simulator

* Variables and Strings
array1  ds.l    10  ; 10 long word array
prompt  dc.b    'Enter a number: ',0    ; null terminated string
result  dc.b    'Your numbers are: ',0  ; null terminated string
crlf    dc.b    $d,$a,0                 ; carriage return, line feed, null

    END START       ; last line of source

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Sun Apr 12, 2009 3:45 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
dark wrote:
How do i go about converting an entry to uppercase. Thank u

The ASCII code for 'a' is $61
The ASCII code for 'A' is $41
A difference of $20.
Subtract $20 from lowercase to convert to uppercase.
Add $20 to uppercase to convert to lowercase.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: Uppercase
PostPosted: Sun Apr 12, 2009 8:07 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
I get how to convert a character to uppercase, but as it relates to a string, is the a way to map across the entire string? or do i have to convert 1 by 1?

Just wanna say thanks :D



Code:

CR      EQU     $0D             EQU assigns the value in the operand column
LF      EQU     $0A             to the label in the label column. In this
*                               case hex 0D and 0A: ASCII code for Carriage
*                               Return and Line Feed (needed for new line)
START   ORG     $1000

*-------Code for output------
        LEA     MESSAGE,A1      Loads MESSAGE into address register A1
        MOVE.B  #14,D0          Moves the number 14 into data register D0
        TRAP    #15             Displays Message
       
MESSAGE DC.B    'hello word',CR,LF,0 ; How do i convert this string to upper case?
   
MESSAGE SUB.B $20,DC.B            ??I'm really not getting and i'm yet to find a good guide? Is this valid?

        MOVE.B  #9,D0
        TRAP    #15             Halt Simulator

        END     START



Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 11:20 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
You must convert the characters 1 by 1.

Note!
Code:
   SUB  $20,D0
does not subtract $20 from D0, it subtracts the contents of memory location $20 from D0. Use:

Code:
   SUB #$20,D0
to subtract $20 from D0.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 3:25 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir thanks for info. Can I do a strlen of MESSAGE and then LOOP through decrementing length by one while subtracting 20 from each character? Do you have any example of how to do this if it is possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 11:08 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
Process the characters 1 by 1 until the null character (0) is reached or hard code the length of the string in your program.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: Re: Uppercase
PostPosted: Sun Apr 19, 2009 9:26 am 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Code:

CR      EQU     $0D             EQU assigns the value in the operand column
LF      EQU     $0A             to the label in the label column. In this
*                               case hex 0D and 0A: ASCII code for Carriage
*                               Return and Line Feed (needed for new line)
START   ORG     $1000

*-------Code for output------
        LEA     MESSAGE,A1      Loads MESSAGE into address register A1
        MOVE.B  #14,D0          Moves the number 14 into data register D0
        TRAP    #15             Displays Message
       
MESSAGE DC.B    'hello word',CR,LF,0 ; How do i convert this string to upper case?
   
MESSAGE SUB.B $20,DC.B            ??I'm really not getting and i'm yet to find a good guide? Is this valid?

        MOVE.B  #9,D0
        TRAP    #15             Halt Simulator

        END     START



If i have a macro called



delete1Char, how do I go about applying it so that result comes back without the first Char.


I am basically asking how do I go about applying a macro


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 19, 2009 11:16 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
The instruction SUB.B $20,DC.B is not valid.

The instruction SUB.B $20,D0 will get a byte of data from memory location $20 and subtract that byte from register D0. (not what you want to do).

The instruction SUB.B #$20,D0 will subtract the literal number $20 from register D0.

The instruction SUB.B #$20,(A1) will subtract the literal number $20 from the byte in memory at the address contained in register A1.

Something like this:


Code:
CR      EQU     $0D             EQU assigns the value in the operand column
LF      EQU     $0A             to the label in the label column. In this
*                               case hex 0D and 0A: ASCII code for Carriage
*                               Return and Line Feed (needed for new line)
START   ORG     $1000

*-------Code for output------
        LEA     MESSAGE,A1      Loads MESSAGE into address register A1
        MOVE.B  #14,D0          Moves the number 14 into data register D0
        TRAP    #15             Displays Message
       
        lea     message,A1      A1 points to string
*       while (A1) is not NULL
*         if (A1) is lower case letter
*           sub.b #$20,(A1)     convert to upper case
*         endif
*         add 1 to A1           point to next character
*       endwhile

   
        MOVE.B  #9,D0
        TRAP    #15             Halt Simulator
       
* variables and constants below this point

MESSAGE DC.B    'hello word',CR,LF,0 ; How do i convert this string to upper case?

        END     START

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: MACRO
PostPosted: Sun Apr 19, 2009 8:25 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir I I understand the code is not working, I just want to know how to apply a macro


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 19, 2009 9:11 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
Check out the program MACRO.X68 in the Examples folder of EASy68K.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: r
PostPosted: Mon Apr 20, 2009 8:44 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir I tried to input strings in your array example and for some reason its not working, can you tell me why and how to fix it to allow strings?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 21, 2009 12:23 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
Trap task 2 will read a string and store it at (A1). Load A1 with the address of a buffer large enough to hold the string then do:
Code:
        move.b #2,d0
        trap   #15

The ASCII code for each character is placed in memory beginning at the address contained in A1.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: ld
PostPosted: Tue Apr 21, 2009 12:51 am 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir I am wondering, to display the string ds.l should I use trap 13 or 14? Please help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 21, 2009 3:21 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1083
task 13 or 14 will work.

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 3 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