EASy68K  
It is currently Mon Feb 24, 2020 9:21 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Help with basic code
PostPosted: Wed Jan 15, 2020 12:34 pm 
Offline

Joined: Fri Dec 13, 2019 8:57 am
Posts: 2
Hello everyone!

I am trying a new programme, easier than the other but I'm a little stuck with the code, I was studying a bit more (searching text in spanish) and now I think I understand this type programming mode a little,

So my first program is about simply arithmetics, I have two constants 70 and 150 and I have to make the sum and then divide the result by 2, so here is my first try:

Code:
Exercise   IDNT   1,1           *Program name
      ORG   $2000   *Location of the program
      JMP   Inicio   *Jump to first instruction

Variables
A      DC.W   70   *Give A the value 70
B      DC.W   150   *Give B the value 150
Suma   DS.W   1   *Result of the sum
Enc      DS.W   1   *Total result

Main program
Inicio   MOVE.W A,D0   *Copy variable to register D0
      MOVE.W B,D1   *Copy variable to register D1
      ADD.W D0,D1   *Sum the values of D0 and D1
      MOVE.W D1,Suma   *Storage the result in Suma
      MOVE.w Suma,D2   *Copy variable to register D2
      DIVU D2/#2               *Make Suma/2
      MOVE.W Enc,D2   *Copy variable to register D2
Fin      STOP #$2700   *Ends program
      END


I think the result is storaged in D2...right?

Ok and secondly I have to write a program which have to write a message if the number is lower than 500, if is between 500 and 1000 and if is greater than 1000

Quote:
Ejercicio IDNT 1,2
ORG $2000
JMP Inicio
Constants
Val1 EQU 232 *This is the def o the value cause I don't know how to read an imput value

Variables
Ingreso DC.W Val1
Min DC.W 500 *Give Min the value 500
Max DC.W 1000 *Give Max the value 1000
Msg1 DC.B 'Los ingresos han sido < 500'
Msg2 DC.B 'Los ingresos han sido > 500 e < 1000'
Msg3 DC.B 'Los ingresos han sido > 1000'

Main program
Start MOVE.W Min,D0 *Copy variable Min to register D0
MOVE.W Max,D1 *Copy variable Max to register D0
MOVE.W Val1,D2 *Copy variable Val to register D2
If1: *first conditional
CMP.W D2,D0 *Compare registers D0-D2
BHI.S else1 *Jump if D2 < D0
LEA Msg1,A1 *Loads message 1 in register A1
MOVE.B #14,D0 *Copy number 14 to adress D0 for task 14
TRAP #15
BRA.S finif1
finif1: *end of first conditional
If2: *second conditional
CMP.W D1,D2
BHI.S else1 *Jump if D2 > D0
LEA Msg2,A2
MOVE.B #14,D0
TRAP #15
BRA.S finif1
finif2:
If3:

CMP.W D1,D2
BHI.S else1
LEA Msg2,A2
MOVE.B #14,D0
TRAP #15
BRA.S finif1

finif3:

I have problems with the third condition because I don't know how to add the >500 AND <1000

Someone please can explain me the conditionals? something similar to write this on assambler;

IF <condition>
body
ELSE
body
ENDIF

Also the use of AND please

IF <condition AND condition>
body
ELSE
body
ENDIF


Top
 Profile  
 
 Post subject: Re: Help with basic code
PostPosted: Thu Feb 20, 2020 9:06 pm 
Offline

Joined: Thu Feb 20, 2020 8:02 pm
Posts: 12
Hello !

1 If you have 2 positive constants 70 and 150 want to add them then divide by two, the simplest is
Code:
        constant1: dc.b 70
        constant2: dc.b 150
        move.w constant1,d0
        add.w constant2,d0 ; you can add from memory, no need to load into a register first
        lsr.w #1,d0  ; for dividing/multiplying by powers of 2, bit shifting is much quicker that divu!



2 About how to represent an "AND" condition: you test each condition in sequence and after each test, you branch out if the condition is false. e.g.
Code:
if:      tst.w <condition1>
         bne  else
         tst.w <condition2>
         bne else
then: ...do something
         bra endif
else:  ... do something else
endif:


For you, the tests will be
Code:
        cmp.w #1000,d0
        bhs else
        cmp.w #500,d0
        bls else


testing if d0 >= 1000 (cmp.w #1000,d0and d0 >= #501 and use bhs
Does it make sense ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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:  
Powered by phpBB® Forum Software © phpBB Group