It is currently Fri Jun 05, 2020 4:56 pm

 All times are UTC

 Page 1 of 3 [ 35 posts ] Go to page 1, 2, 3  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Convetr to Upper Case & ArraysPosted: Sun Apr 12, 2009 12:15 pm

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

 Post subject: Posted: Sun Apr 12, 2009 3:42 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: Re: Convetr to Upper Case & ArraysPosted: Sun Apr 12, 2009 3:45 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: UppercasePosted: Sun Apr 12, 2009 8:07 pm

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

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

 Post subject: Posted: Mon Apr 13, 2009 11:20 am

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: Posted: Mon Apr 13, 2009 3:25 pm

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

 Post subject: Posted: Mon Apr 13, 2009 11:08 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: Re: UppercasePosted: Sun Apr 19, 2009 9:26 am

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

 Post subject: Posted: Sun Apr 19, 2009 11:16 am

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: MACROPosted: Sun Apr 19, 2009 8:25 pm

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

 Post subject: Posted: Sun Apr 19, 2009 9:11 pm

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

_________________
Prof. Kelly

Top

 Post subject: rPosted: Mon Apr 20, 2009 8:44 pm

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

 Post subject: Posted: Tue Apr 21, 2009 12:23 am

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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

 Post subject: ldPosted: Tue Apr 21, 2009 12:51 am

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

 Post subject: Posted: Tue Apr 21, 2009 3:21 am

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

_________________
Prof. Kelly

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 3 [ 35 posts ] Go to page 1, 2, 3  Next

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 12 guests

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

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects