EASy68K  
It is currently Tue Dec 10, 2019 5:12 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Fri May 29, 2009 10:24 am 
Offline

Joined: Fri May 29, 2009 4:15 am
Posts: 5
Location: Queensland Australia
Assistance please anyone.

I came across this piece of code below

Obviously it for an addition subroutine (this I understand) - but can someone please explain what is the purpose/logic of the following highlighted code (the comment is therefore not even understood - why 3*4?? - the routine is part of a numeric equation with multi operand input operations (single digit only) )

ADDFUN LEA ADDFUN,A4 set return addr
ADDA #12,A4 offset (3*4) to set return JSR READC get next character
MOVE.B (-2,A6),D0 retrieve operand 1
ADD.B (-1,A6),D0 add operand 2
BRA DONE for now!

Also what does the -2 and -1 do (purpose)

Please dont refer me to net resources on 68k - I've scoured them all out of necessity - the recommended text I have has NOTHING on 68000 (yet this is the language being taught - there are so many more informative books out there on 68k from my research - its too late to get one now tho (exam in one week))

ps I have zero programming knowledge (welcome to programming by distance education - thats my challenge)

thanks

_________________
Is this what they speak on earth - I'll try and work it out but I cant promise - a little translation is really appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 29, 2009 11:28 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
Without the entire program I can't say for sure what the code is doing but it is probably something like ths:

ADDA #12,A4 is probably adjusting register A4 to make room for 3 long words. Each long word is 4 bytes in memory so 3*4. Address registers are most commonly used as pointers so this is probably some pointer math.

MOVE.B (-2,A6).D0 The -2 also does pointer math. It subtracts 2 from the address in A6. The resulting number is used as a pointer (indirect address). If A6 contained the value $1234 then the above instruction would get the byte of data from address $1232 and place it in register D0.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Sat May 30, 2009 5:16 am 
Offline

Joined: Fri May 29, 2009 4:15 am
Posts: 5
Location: Queensland Australia
Thanks Professor Kelly

Actually here is the complete code - it is close to a task I must do (arithmetic operations) but it doesnt meet all the required parameters so I will have to fathom that part out eg must permit 3 digit input and negative results, no variables needed etc etc - this code below only caters to positive single digit

But here is the full code which was compiled by Paul Jay - I forget which site I located his code on - but it has given some guidance as to my task (tho no doubt there are various ways to code aspects of the task) e.g. I see someone asked you about Input Equation - no doubt for this same task

Regards


* Description : Basic arithmetic with variable storage
* Details : Accepts input in the form [operand1] [operand] [operand2].
* The brevity in design of this program restricts operands
* to whole numbers and rounds all results of divisions for
* compatability. Negative differences will be treated as if
* they were positive. After the calculation has been per-
* formed, the user will have the option to store this val-
* ue in a letter variable. If no letter is input, no ass-
* ignment will be made. Stored variable letters can then
* be input in place of whole numbers.


ORG $2500
CNT DC.B 'Continue? (y)'
ORG $3000
MSG DC.B 'Enter two whole numbers seperated by an operator, assigned vars can be used:'
ORG $4000
VAR DC.B 'Assign to var?'

START ORG $1000
LEA $3000,A1 set addr of banner str
MOVEQ #76,D1 set banner len
MOVEQ #0,D0 set trap for disp str
TRAP #15 disp banner
MOVEA #0,A1 reset A1
LEA $1000,A6 get addr of user mem
MOVEQ #2,D0 set trap for str in
REPEAT TRAP #15 get str
MOVEA.L #0,A0 reset A0
SUBQ #2,D1 offset str len
READC MOVE.B (A0)+,D0 get next char
CMP.B #$30,D0 is this a number?
BLT OPRND if not, test for opr8r
CMP.B #$60,D0 is this a ltr?
BGT GETV retreive var
SUBI #$30,D0 get dec equiv
GOTV MOVE.B D0,(A6)+ push onto mem
DBRA D1,READC repeat
JMP (A4) pointer to calling sub (set by sub)

OPRND IF.B D0 <EQ> #$2D THEN is the operator "-"
BRA SUBFUN
ENDI
IF.B D0 <EQ> #$2B THEN is the operator "+"
BRA ADDFUN
ENDI
IF.B D0 <EQ> #$2A THEN is the operator "*"
BRA MULFUN
ENDI
IF.B D0 <EQ> #$2F THEN is the operator "/"
BRA DIVFUN
ENDI
RTS

ADDFUN LEA ADDFUN,A4 set return addr
ADDA #12,A4 offset (3*4) to set return
JSR READC get next character
MOVE.B (-2,A6),D0 retrieve operand 1
ADD.B (-1,A6),D0 add operand 2
BRA DONE for now!

SUBFUN LEA SUBFUN,A4 set return addr
ADDA #12,A4 offset (3*4) to set return
JSR READC get next character
MOVE.B (-2,A6),D0 retrieve operand 1
SUB.B (-1,A6),D0 subtract operand 2
BRA DONE for now!

MULFUN LEA MULFUN,A4 set return addr
ADDA #12,A4 offset (3*4) to set return
JSR READC get next character
CLR.W D1 cleanup...this will be handle by seperate routine
MOVE.B (-2,A6),D0 retrieve operand 1
MOVE.B (-1,A6),D1 retrieve operand 2
MULU D1,D0 return here and multiply
BRA DONE now disp

DIVFUN LEA DIVFUN,A4 set return addr
ADDA #12,A4 offset (3*4) to set return
JSR READC get next character
CLR.W D1
MOVE.B (-2,A6),D0 retrieve operand 1
MOVE.B (-1,A6),D1 retrieve operand 2
MOVEQ #10,D2 assume ops are < 10
DIVU D1,D2
MULU D2,D0
DIVU #10,D0 GET FIRST DIGIT
MOVE.B D0,D1 STORE IN D1
SWAP D0 GET SECOND DIG
CMP.B #5,D0 IS SEC DIG >= 5
BLT RND IF NOT, ROUND DOWN
ADDQ #1,D1 ROUND UP
RND MOVE.B D1,D0 RESTORE
BRA DONE now disp

DONE MOVE.W D0,D1 move for disp
MOVEQ #3,D0 set trap
TRAP #15 disp result
MOVE.W D1,D6 get copy of result
MOVEQ #3,D1 incr line cnt
MOVEQ #11,D0 set D0 for pos
TRAP #15 next disp line
BRA ASSV assign result to var?

RETV MOVEQ #5,D1
MOVEQ #11,D0
TRAP #15
LEA $2500,A1 get addr continue str
MOVEQ #13,D1 set len
MOVEQ #0,D0 set trap
TRAP #15 continue?
MOVEQ #5,D0 set trap
TRAP #15 get resp
CMP.B #$79,D1 is resp y?
BNE QUIT
MOVE.W #$FF00,D1 clrscr val
MOVEQ #11,D0 clrscr
TRAP #15 clear scrn
LEA $0,A1

CLEAN CLR.L D0 begin reset DR
CLR.L D1 .
CLR.L D2 .
CLR.L D3 .
CLR.L D4 .
CLR.L D5 .
CLR.L D6 .
CLR.L D7 end reset DR
MOVEA A5,A1 begin reset addr
MOVEA A5,A2 .
MOVEA A5,A3 .
MOVEA A5,A4 .
MOVEA A5,A6 end reset addr
MOVEQ #2,D0
BRA REPEAT start over

ASSV LEA $4000,A1 get addr of var prompt
MOVEQ #14,D1 get msg len
MOVEQ #0,D0 set trap
TRAP #15 disp var?
MOVEQ #5,D0 set trap
TRAP #15 get response
ADDA D1,A2 incr addr offset
MOVE.B D6,(A2) put value in var store
MOVEA A5,A2 restore addr
BRA RETV go back

GETV ADDA D0,A2 get offset for var
MOVE.B (A2),D0 put the val in D0
MOVEA A5,A2 restore addr
BRA GOTV

QUIT STOP #$2000
END START

_________________
Is this what they speak on earth - I'll try and work it out but I cant promise - a little translation is really appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 01, 2009 12:46 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
I would not recommend using this example as a starting point. It uses some very unstructured code (assembly language tricks) that I do not recommend for someone trying to learn assembly language programming.

Just approach this problem as you would any programming assignment.

1. Work out the logic. I require my students to create a flow chart or pseudocode.

2. (optional) Code the solution in your favorite "high level" language. This is a great way to verify your logic.

3. Code the solution in assembly language. Start small, one routine at a time. Test it, Save it, and move on to the next.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: Re favourite code
PostPosted: Mon Jun 01, 2009 3:22 pm 
Offline

Joined: Fri May 29, 2009 4:15 am
Posts: 5
Location: Queensland Australia
Hi Prof Kelly

Well unfortunately therein lies the probelm - this is the first true programming subject I have done - while I am used to looking at html for web design - assembly code seems to be on another level (despite those who claim it is easy to learn) - if you could read the posts by many students in my course you would be horrified as no doubt our tutors are - I am definitely not the only one having trouble thats for sure - had a few issues that affected my study (despite doing this by distance learning) but I had to drop another subject as this one has taken up 3 or 4 times the study needed compared to other subjects - fortunately I do not intend working in IT but I am aiming for an IT degree (I am an accountant by background - 20 odd years).

In any case I have actually modified this program greatly to try to use it for my "base" code (and I will acknowledge this to my tutors and get marked accordingly) - the things I had trouble with are threefold

• identifying where in this code I need to / can change the input values to permit more than one digit - I realise this is the data size in the register but I have gone thru this program (my amended version) step by step and cant work out what to change - I have been puzzling over this for 2 days easily now

• I also must permit negatives - in the end I will simply pass on resolving that as time is very much against me (exam this week and assignment now overdue)

• lastly I cant seem to include the output (wording) - I can still produce the actual result

My main issue is trying to edit this code to permit multiple numbers - stepping thru the code while running it and changing what I thought were the appropriate lines did not work - I would be happy if I can at least manage that !!

Without telling me the answer perhaps you could point me in the right direction

Our materials have not been the best (and we used no text book in fact) - a lot of dissatisfaction due to those issues - I bought the suggested text (which we did not need reputedly - and given that did not include 68k at all - I can see why) - I have over the weeks of my course noted many more relevant (older) texts online - despite all that I intend to pass I hope

Thank You

_________________
Is this what they speak on earth - I'll try and work it out but I cant promise - a little translation is really appreciated!!


Top
 Profile  
 
 Post subject: Re: Re favourite code
PostPosted: Mon Jun 01, 2009 7:25 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
What I've done here is make a skeleton program for you that you should find a little easier to understand and modify.

It currently accepts expressions such as 123+456, and also works with subtract, multiply and divide. It outputs an error message if the expression is faulty, but it doesn't check the number of digits entered (numbers entered must fit in 16 bits). There should also be no spaces in the expression, there are no variables (as you said), and only the output is signed (which only happens with subtract). The program also doesn't loop back to the beginning, add it yourself. Results larger than 16 bits are unreliable. There is also no rounding of divided results.

The program doesn't handle signed input. Handling signed input is actually not very hard to do (there's an instruction that makes makes numbers negative, for example).

All in all, I didn't give you the whole answer, just like you asked, but this should still be more helpful than the code you posted.
Code:
;-----------------------------------------------------------
; Program     : Simple Calculator Skeleton.
; Written by  : Thorham
; Date        : 1 june 2009
; Description : Handles simple experssions.
;-----------------------------------------------------------
    org  $1000
start:                  ;first instruction of program
 
input_expression
    moveq   #13,d0      ;Show instructions.
    lea     prompt,a1
    trap    #15

    moveq   #2,d0       ;Get keyboard input (0 terminated string).
    lea     input,a1    ;Point a1 to string location.
    trap    #15

evaluate_expression
    lea     expression,a2 ;Binary storage for the expression.
    lea     input,a3    ;Point a3 to obtained string.
    moveq   #0,d2       ;Clear reg used for converting decimal to binary.

loop
    move.b  (a3)+,d0    ;Get character from obtained string.
    beq     end_loop    ;If it's a 0, then end of expression reached.

    cmp.b   #'+',d0     ;Test for +, -, *, / signs.
    beq     operator
    cmp.b   #'-',d0
    beq     operator
    cmp.b   #'*',d0
    beq     operator
    cmp.b   #'/',d0
    beq     operator

    cmp.b   #'0',d0     ;Test for digits.
    blt     invalid     ;If it's not a digit, then the input is faulty.
    cmp.b   #'9',d0
    bgt     invalid

digit
    sub.b   #'0',d0     ;Convert digit to binary
    mulu    #10,d2      ;and add it to the register
    add.w   d0,d2       ;used for decimal to binary conversion.

    bra     loop        ;Do next char in expression.

operator
    move.l  d2,(a2)+    ;Store first number.
    moveq   #0,d2       ;Clear conversion register again.

    move.l  d0,(a2)+    ;Store operator.
    bra     loop        ;Next part of the expression.

end_loop
    move.l  d2,(a2)     ;Store second number.

    move.l  (a2),d2     ;Get first number.
    move.l  -(a2),d3    ;Get operator.
    move.l  -(a2),d4    ;Get second number.
   
    cmp.b   #'+',d3     ;Test which operator, and jump acordingly.
    beq     add_numbers
    cmp.b   #'-',d3
    beq     sub_numbers
    cmp.b   #'*',d3
    beq     mul_numbers
    cmp.b   #'/',d3
    beq     div_numbers

add_numbers
    add.w   d2,d4       ;Add the two numbers.
    bra     show_result

sub_numbers
    sub.w   d2,d4
    bra     show_result

mul_numbers
    mulu    d2,d4       ;Multiply the two numbers.
    bra     show_result

div_numbers
    divu    d2,d4
    swap    d4          ;
    move.w  #0,d4       ;Clear remainder.
    swap    d4          ;

show_result
    moveq   #3,d0
    move.l  d4,d1
    ext.l   d1          ;Extend results sign to 32 bit (needed for display routine).
    trap    #15

    bra     exit

invalid
    moveq   #13,d0
    lea     error,a1
    trap    #15

exit
    move.b  #9,d0
    trap    #15         ;halt simulator

;
; variables and strings
;
expression
    ds.l    3
input
    ds.b    80      ;reserved space for input
prompt
    dc.b    'Enter two numbers seperated by an operator:',0
error
    dc.b    'The expression entered is invalid.',0
space
    dc.b    ' ',0

    end   start       ;last line of source


Top
 Profile  
 
 Post subject: re suggested code
PostPosted: Tue Jun 02, 2009 12:27 am 
Offline

Joined: Fri May 29, 2009 4:15 am
Posts: 5
Location: Queensland Australia
Thanks for that

I'll have a look at that in close detail and obviously run it - and compare it to my edited version of the other code to see what I may be doing wrong (or dont understand)

I know I am trying to edit as Prof Kelly indicated a non-beginner code. Your code will help me understand some basics. Generally I can follow the processes >> of course you need to know what the code means - but its the intricacies of "why" certain code is done a certain way - thats invariably what not be well explained (certainly in our course that has been the gripe of many and some have literally given up sadly (not all subject deliveries have been like this fortunately!!! I have several very good results from previous (Level 3 subjects) - this is suppose to be Level 1 - I have been doing quite well in this subject - but due to time consumed have hit a stumbling block as the programming went from very very basic to much more complex (without those essential explanations) - those with programming experience no doubt have had a much easier time)

I must say I am surprised that I found it quite hard to locate on the net (excluding your example) suitable easy68k examples of code for more simplistic tasks such as basic arithmetics e.g. multi-operand - plenty showing eg to add do this - but to combine all those functions thats where many students come crashing down!!

From my student perspective all the downloadable easy68k examples are very nice (those on this site and others I have come across) but it would be great (certainly for those poor distance education students who to a certain extent operate on 90% their own efforts (almost being self taught depending on quality of learning materials)) to have a few more basic examples of basic pc operations - which obviously might include combinations of arithmetic equations (as per this very assignment I must comprehend)

I certainly wont forget 68k after this subject and am actually challenged to continuing learning more about it - I certainly hate things I dont understand - 68k is reasonably simple code I know - as they say - practice makes perfect.

Thanks so much for your help (also to Prof kelly)

Cheers

_________________
Is this what they speak on earth - I'll try and work it out but I cant promise - a little translation is really appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 02, 2009 12:57 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
It is unfortunate that your first experience with assembly language and EASy68K was without prior programming experience. We require our students to complete 2 prior courses in programming before they may take assembly language. It is possible to learn assembly language as a first language (that's what I did) but it is generally not the best approach and certainly not recommend by distance learning and without a very good textbook.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 02, 2009 4:52 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
notsoeasy wrote:
Thanks for that
You're welcome :thumbup:
notsoeasy wrote:
I know I am trying to edit as Prof Kelly indicated a non-beginner code.
Well, to be honest, that code isn't the best code generally speaking. The author takes a difficult approach to a pretty basic problem, and he ends up using some hacks witch are unnecessary. If I were you, I wouldn't use that code. It's harder to understand, it's more difficult to extend, and it does some things witch it shouldn't do.

Anyway, I hope you succeed. The road you've taken is not the easiest, and in fact I can only imagine how hard is must be to learn programming using 68k assembler as your first language. Good luck.

If you have any more questions, feel free to ask them.


Top
 Profile  
 
 Post subject: Getting easier!?!!
PostPosted: Wed Jun 03, 2009 12:17 am 
Offline

Joined: Fri May 29, 2009 4:15 am
Posts: 5
Location: Queensland Australia
Hi Thorham

Thanks for the encouragement & assistance all round from yourself/Prof Kelly

I have in the end dispensed with my original attempt which was based on the original code presented in the forum (but heavily edited) I could say was almost 75% my own "understanding"). I have drawn on much of your code (which probably gave too much help) - I have acknowledged a third party mentor at least (and given the difficulties not just with learning programming from scratch (espec 68k) but even Prof Kelly's own comments about prior programming pre-requisites) - I think distance students need a mentor for a subject like this - moreso if the support materials dont really give 'enough' explanations.

I managed to some of the extra changes needed - the code was required to loop back for repeat processes - I added that in but maybe not handled the best way as there must also be a terminate command - my actual input (repeat process) failed to change the result (which I found a bit odd as what I did was CLR the registers (correct??) prior to that - but something did not work so well (I will go back and be reviewing what needs fixing as soon as I have time) - once I get a result (which invariably takes forever) - I'll post it back here - there are other intricacies needed but due to timeframe I had to abandon attempts at their inclusion

One last question >> relating to "IDEAL" textbook >> possibly Prof Kelly might care to comment - given the 68000 is not exactly a new technology - what one book would you recommend for beginners in 68k - Ford & Topp has an extensive preview on Google Books - seems to highly suitable as a text - any others? Or maybe Antonakos (68000 Microprocessor)?

I've gone off the original thread here now I guess. Thanks

Cheers

_________________
Is this what they speak on earth - I'll try and work it out but I cant promise - a little translation is really appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 03, 2009 1:04 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1109
I have not used those books in my classes but the content looks good. I have been using a book by Alan Clements but it has gone out of print.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 03, 2009 10:01 am 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
notsoeasy wrote:
I have drawn on much of your code (which probably gave too much help)

Don't worry about too much help. In the beginning there really isn't something like too much help, trust me. Also, the most important part is trying to fully understand the example program I gave you. Without any general purpose programming experience this is going to be hard enough as it is.
notsoeasy wrote:
- I have acknowledged a third party mentor at least (and given the difficulties not just with learning programming from scratch (espec 68k) but even Prof Kelly's own comments about prior programming pre-requisites) - I think distance students need a mentor for a subject like this - moreso if the support materials dont really give 'enough' explanations.

Good to hear that. Yes, if you're learning this from scratch, then you can use all the help you can get.
notsoeasy wrote:
I managed to some of the extra changes needed - the code was required to loop back for repeat processes - I added that in but maybe not handled the best way as there must also be a terminate command - my actual input (repeat process) failed to change the result (which I found a bit odd as what I did was CLR the registers (correct??) prior to that - but something did not work so well (I will go back and be reviewing what needs fixing as soon as I have time) - once I get a result (which invariably takes forever) - I'll post it back here - there are other intricacies needed but due to timeframe I had to abandon attempts at their inclusion

Post the code so I can have a look at it. As for the abandoned things, try to add them later in your own time, a slow start is not necessarily a bad thing (except when the grades weigh heavily, witch they shouldn't in the beginning).
notsoeasy wrote:
One last question >> relating to "IDEAL" textbook >> possibly Prof Kelly might care to comment - given the 68000 is not exactly a new technology - what one book would you recommend for beginners in 68k - Ford & Topp has an extensive preview on Google Books - seems to highly suitable as a text - any others? Or maybe Antonakos (68000 Microprocessor)?

I've included some links here:

This is the book I used to learn 68000. It's an Amazon link (no picture of the book, sadly):

Assembly Language Programming for the 68000

Motorolas programmers reference from Freescale (may be unsuitable for beginners, but could be useful):

68000 Family Programmer's Reference Manual Also deals with the other cpus in the 68000 family. PDF format.
68K Programmer’s Reference Manual Errata PDF format.

Some 68k courses. These are suitable for beginners (some are Amiga oriented, but this shouldn't matter much as Amigas are 68k based):

Principles of Computers II Scroll down for the relevant links. Looks messy.
ChaoZers Assembler Tutorial Page This one is Amiga oriented, but seems to be quite good. Spread over seven text files.
AmigaMachine.lha This one is also Amiga oriented, but again, seems to be quite nice. Use WinRar to unpack.

Amiga releted forum with a coders section at the bottom (Coders Heaven). Most of the activity in the coders section is 68k assembler related. May be useful:

English Amiga Board

Don't worry about the Amiga specific things, the two courses I've provided don't seem to deal with these things until after dealing with 68000 assembler. They simply continue after assembler and go into Amiga hardware programming witch you can simply ignore. I've included them because they seem to teach the assembler subject quite well.

If you have any trouble accessing the linked content, I can send them to you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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