EASy68K  
It is currently Thu Apr 02, 2020 1:04 pm

All times are UTC




Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Tue Apr 21, 2009 4:45 am 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir for some reason when I use the task 2 with the code you provided it doesn't work. I do a memory lookup and the entry is there just not getting added to the array and I'm just frustratedo I guess I'm doing something wrong. Thanks for all your help sir, it was great.


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

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Here is an example program that prompts the user to enter their name, reads their name into a buffer then displays a greeting with their name.


Code:
*-----------------------------------------------------------
* Written by    : Chuck Kelly
* Date Created  : April-2009
* Description   : Demonstration of text input and output
*-----------------------------------------------------------
   ORG   $1000
START:            ; first instruction of program

* prompt for name
    lea     prompt,A1
    move.b  #14,d0
    trap    #15
   
* read name and store in buffer
    lea     buffer,A1
    move.b  #2,d0
    trap    #15

* display Hello + name
    lea     hello,A1
    move.b  #14,d0
    trap    #15
   
    lea     buffer,A1
    move.b  #14,d0
    trap    #15
   
* program end
   MOVE.B   #9,D0
   TRAP   #15      ; halt simulator

* Variables and Strings
buffer  ds.b    80                      ; text buffer
prompt  dc.b    'Enter your name: ',0
hello   dc.b    'Hello ',0

   END   START      ; last line of source

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 21, 2009 9:06 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Sir thanks for that great example it really helped. I created an array ds.l 20 to store data, it stores numbers and chars just fine, but the strings were not stored. I even tried a move the buffer to the array at address A0 and still displayed everything but the string. I don't think the string is been added to the array. Can a string be added to the array? Where am I going wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 22, 2009 10:33 am 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
This is what I have, but the string is not being added to the array. What am I doing wrong? I want to add the strings to the array then display them

Code:

    ORG $1000
SIZE    equ     4   ; data size (4 bytes for long word)

START:              ; first instruction of program

    * read 10 strings  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
       
        lea buffer,A1
        move.b  #2,D0       ; read string  from keyboard into D1.L
        trap    #15
               
        move.l  D1,(A0,D2)  ; store the string 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 string from array at index D0
        ;lea buffer, A1
   move.b  #14,D0       ; display string  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
buffer  ds.b    80
prompt  dc.b    'Enter a name: ',0    ; null terminated string
result  dc.b    'Your names are: ',0  ; null terminated string
crlf    dc.b    $d,$a,0                 ; carriage return, line feed, null

    END START       ; last line of source



Last edited by dark on Wed Apr 22, 2009 6:47 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 22, 2009 5:04 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Your first problems are here ..

Code:
      lea         buffer,A1
      move.b      #2,D0       ; read number from keyboard into D1.L
      trap        #15

.. it doesn't help that you haven't changed the comments but if you look at the code you're setting the same address for each string with the lea buffer,A1 so any saved string is overwritten by the next one. What you need to do is set up an array of strings with enough room for each string.

Your next problems are here ..

Code:
      lea         array1,A0   ; pointer to array
   
...

      move.l      (A0,D2),D1  ; get number from array at index D0
      move.b      #14,D0      ; display number in D1.L
      trap        #15

Earlier in the program you set A0 to point to an array of longword numbers, which you filled with the input string lengths, and you're trying use the string lengths as pointers to the strings. Unfortunately you're not even putting these nukbers in the right register, A1, but D1. I'm guessing theat the program outputs the result string 'Your names are: ' twice followed by lots of line feeds.

You also didn't change the comments to match the new code, if you had you may have seen your errors.

Lee.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 22, 2009 7:02 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
Thanks lee, lol. Just looked back it, changed the comments and the answer was there staring me in the face, thanks a million


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 28, 2009 7:01 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
I wrote a uppercase function that converts the value entered by a user to uppercase. For some reason when I try to save the buffer to the array its not working



Code:

lea buffer, a1                   ;load address of buffer into A!
move.b #2, d0                 ;store data into d1.l
trap #15

move d1, counter
bsr uppercase

* I am wondering if after the subroutine is called the result is stored back in buffer


If i do a print of the data in buffer it works, just not going in the array converted

I'm thinking i should probably convert the data while removing it from the array


The procedure i use to read in an array location is:

Code:

lea temp, a6

** Code truncated

lea (A6,D2),A1
move.b #2, D0
trap #15


when reading out:

Code:
move.l (A4,D2), D1
move.b #14, D0
trap #15



How would i go about applying my uppercase subroutine while the data is being read out?


Last edited by dark on Thu Apr 30, 2009 7:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 30, 2009 2:47 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Can you show all the code? It's not clear from these excerpts exactly what you are doing.

Lee.


Top
 Profile  
 
PostPosted: Mon May 04, 2009 11:46 pm 
Offline

Joined: Sun Apr 12, 2009 12:10 pm
Posts: 13
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   
        move.b  #13,D0   
        trap    #15
       
        lea buffer,A1     
        move.b  #2,D0       
        trap    #15

        move.l  (buffer),(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),D0   
        lea (A0,D2),A1
        move.b  #14,D0     
        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


newLine   lea     crlf,A1     ; pointer to string
          move.b  #14,D0      ; display cr lf
          trap    #15
     rts 

* Variables and Strings
array1  ds.l    10  ; 10 long word array
buffer  ds.b    80
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
blen  ds.w    1

    END START       ; last line of source

 

*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~8~



my code seems to be overwriting the array location. What i wanna do is to create a pointer to point to particular locations in memory. Then out back the string.

Do you have any examples of using a while loop instead of a for loop[/code]


Top
 Profile  
 
PostPosted: Tue May 05, 2009 11:14 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Two things I noticed, there may be more issues, I don't have much time at the moment. Perhaps Lee will continue.


dark wrote:
Code:
    for D2 = #0 to #9*SIZE by #SIZE do.s  ; loop 10 times
        lea     prompt,A1   
        move.b  #13,D0   
        trap    #15
       
        lea buffer,A1     
        move.b  #2,D0        <--- This trap task reads an entire string and stores it to buffer.
 Each time the code loops the old string is replaced
        trap    #15

        move.l  (buffer),(A0,D2)  ; <-- This transfers the first 4 characters from buffer to (A0,D2)
    endf
   

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 07, 2009 2:35 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
This is a modified version of the program, where the last problem described has been fixed. I've also removed those high level for instructions, because IMHO they are not assembler, and really don't belong in any 68k code. Note that that comes from my Amiga assembler experience, where it's simply not done, so, sorry about that :)

At first I hadn't tested this code, because it relies on Easy68k's trap setup, which I can't use on my Amiga. I thought the code would work, but I was unsure and downloaded Easy68k, and the local labels which I used didn't work, so I changed them. The code now seems to do what it should do.

Code:
*-----------------------------------------------------------
* Program     : Array programming
* Written by  : Chuck Kelly
* Modified by : Thorham
* Date        : April, 2009
* Description : Get 10 numbers from keyboard, store them in
*              an array then display them from the array.
*-----------------------------------------------------------
    ORG $1000
START:              ; first instruction of program
;
; read 10 numbers from keyboard and store in array
;
    lea     array1,A0           ; pointer to array
    lea     buffer,A2           ; pointer to buffers

        move.l  #9,D2
l1
        lea     prompt,A1   
        move.b  #13,D0   
        trap    #15
       
        move.l  A2,A1
        add.l   #80,A2              ; point to next buffer
        move.b  #2,D0       
        trap    #15

        move.l  A1,(A0)+            ; store number in array

        dbra    D2,l1
   
    lea     result,A1           ; pointer to string
    move.b  #13,D0              ; display result
    trap    #15
;
; display numbers from array
;
    lea     array1,A0           ; pointer to array

        move.l  #9,D2
l2
        move.l  (A0)+,A1
        move.b  #14,D0     
        trap    #15

        lea     crlf,A1             ; pointer to string
        move.b  #14,D0              ; display cr lf
        trap    #15

        dbra    D2,l2
       
    move.b  #9,D0
    trap    #15                 ; halt simulator
;
; Variables and Strings
;
array1  ds.l    10                      ; 10 long word array
buffer  ds.b    80*9                    ; space for 9 buffers
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
blen    ds.w    1

    END START       ; last line of source
Edited: Loops were looping nine times instead of ten, silly typo :)


Last edited by Thorham on Fri May 22, 2009 10:27 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri May 22, 2009 9:37 pm 
Offline

Joined: Sat Oct 18, 2008 11:26 am
Posts: 13
Location: France - 44
There is a faster and shorter way to convert to lower/upper case :
Upper case :
Code:
 BCLR.B #5,<ea>

Lower case :
Code:
 BSET.B #5,<ea>

It avoid testing how is the current character.

_________________
http://www.yaronet.com/blogs/blog.php?id=400


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 22, 2009 10:21 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
Folco wrote:
There is a faster and shorter way to convert to lower/upper case :
Upper case :
Code:
 BCLR.B #5,<ea>

Lower case :
Code:
 BSET.B #5,<ea>

It avoid testing how is the current character.
This only works properly if the input is made up of only alphabet characters. If the input can be any character, then you have to check if the charcter is upper or lower case in the normal way.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 22, 2009 11:57 pm 
Offline

Joined: Sat Oct 18, 2008 11:26 am
Posts: 13
Location: France - 44
I agree. But in all cases, you should check if the character is an alphabet one, with a routine like this one :
Code:
|==================================================================
|   CheckAlpha
|==================================================================
|   Check if a char is a letter or an underscore
|
|   input   d1.b   char
|   output   d0   null if valid
|   destroy   nothing
|==================================================================
CheckAlpha:
   moveq.l   #1,%d0            |default : invalid char
   cmpi.b   #'_',%d1         |underscore ?
   beq.s   ValidAlpha         |yes, it is valid
   cmpi.b   #'A',%d1         |char < A ?
   bcs.s   InvalidAlpha         |so invalid
   cmpi.b   #'Z',%d1         |char < Z ?
   bls.s   ValidAlpha         |so valid
   cmpi.b   #'a',%d1         |char < a ?
   bcs.s   InvalidAlpha         |so invalid
   cmpi.b   #'z',%d1         |char > z ?
   bhi.s   InvalidAlpha         |so invalid
ValidAlpha:
   moveq.l   #0,%d0            |else it's a valid char
InvalidAlpha:
   rts


Then you can apply that without any other test.

_________________
http://www.yaronet.com/blogs/blog.php?id=400


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 25, 2009 6:46 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
Folco wrote:
Then you can apply that without any other test.

Yes, but two things:

1) Why check for an underscore? Also, doing so means you still can't use the btst method.
2) Why check for just general letters if you have to check all four cases anyway? You'll know the case already.

Example:
Code:
;
; Check upper/lower case
;
; d0=char
; d1=return code: -1 for not a letter
;                  0 for upper case
;                  1 for lower case
;
case
    cmp.b   #"A",d0
    blt     case_none
    cmp.b   #"Z",d0
    ble     case_up

    cmp.b   #"a",d0
    blt     case_none
    cmp.b   #"z",d0
    ble     case_low

case_none
    moveq   #-1,d1
    rts

case_up
    moveq   #0,d1
    rts

case_low
    moveq   #1,d1
    rts

This simply returns a value based on the characters case and also checks if the character is not a letter. People should simply forget bittesting for checking a characters case.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 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:  
cron
Powered by phpBB® Forum Software © phpBB Group