Valhalla Legends Forums Archive | Assembly Language (any cpu) | Just for fun...

AuthorMessageTime
iago
Just for fun, here's a Motorola 68k program I wrote for school.  It's not the best written since we're allowed to use a very limited number of instructions.  The purpose is to convert a hex number (in a string) to binary, decimal, and, if possible, ascii:

[code]*****************************************************************
* NAME              iago
* STUDENT NUMBER    666
* COURSE            74.222
* INSTRUCTOR        Sara
* ASSIGNMENT        2
* QUESTION          3
*****************************************************************
*setup low memory
         org       $0
         dc.l      $100000             stack pointer after reset
         dc.l      start               program counter after reset
         org       $1000
*****************************************************************
         include   68kIO.s             Input/Output routines
*****************************************************************
*initialize for I/O
start:    lea       zzduart,a1
         move.b    #%00010000,zzcra(a1)     Reset MR?A pointer
         move.b    #%00100011,zzmr1a(a1)    8 data bits
         move.b    #%00010111,zzmr2a(a1)    Normal Mode
         move.b    #%10111011,zzcsra(a1)    Set clock to 9600
         move.b    #%00000101,zzcra(a1)     Enable Rx and Tx
*****************************************************************
*equ symbols
null      equ       $00                 null string terminator
lf        equ       $0A                 linefeed
cr        equ       $0D                 carriage return
*****************************************************************
* My program starts here
*****************************************************************

main
*Print Identification
     lea      IDBanner,a0         address of IDBanner
     jsr      strout
     jsr      newline

* Get the input values
* Print the prompt
Begin:
     jsr      newline
     lea      GetHex,a0
     jsr      strout

* Input the hex value
     lea      HexStr,a0
     jsr      strin

* d7 = HO Byte
* d6 = LO Byte
* d5 = Decimal Value of byte

* Move half the string into d7
     clr.l      d7
     move.b      (a0)+,d7
* Move the other half into d6
     clr.l      d6
     move.b      (a0),d6

*      jsr      ShowNums

* Clear the decimal byte
     clr.l      d5
* Make d7 and d6 into their decimal values
     sub.l      #'0',d7
     sub.l      #'0',d6

*      jsr      ShowNums

* If d7 is already in decimal, jump over conversion
     cmp.b      #9,d7
     ble      d7IsGood
* Ok, d7 is a hex letter
* The value to subtract is 10 - ('A' - '0') - 1
*                        = 10 - (0x40 - 0x30) - 1
*                        = 10 - 0x10 - 1
*                        = 10 - 16 - 1
*                        = 7
     sub.l      #7,d7
d7IsGood:

* Now do the same for d6
     cmp.b      #9,d6
     ble      d6IsGood
* d6 is hex > 9
     sub.l      #7,d6
d6IsGood:

* Now we multiply d7 by 16 to make it hex
     mulu      #16,d7

* Finally, add them together to get the full decimal value
     add.l      d6,d7

* Here is the easiest place to check for the sentinal, so
* what the heck?
     cmp      #0,d7
     beq      Over
* Display the decimal value
     lea      PutDec,a0
     jsr      strout
     move.l      d7,d0
     jsr      decout

* Make a copy of the number for converting to binary
     move.l      d7,d6
* Load the address of BinStr into a1
     lea      BinStr,a1

* Set up d1 as a counter, and branch to the end of CalcBin
     move.l      #8,d1
     bra      EndBin

* Clear out d2 to store remainder
     clr.l      d2
BegBin:
* Divide d6 by 2
     divu      #2,d6
* Bring the remainder to the front
     swap      d6
* Move the remainder into d2
     move.w      d6,d2
* Get rid of the remainder
     clr.w      d6
* Put the next value to divide back into the LOW
     swap      d6
* Check the remainder, if it's a 1 jump to DoOne, otherwise fall through
     cmp.w      #1,d2
     beq DoOne
* Set the next bit to a zero
     move.b      #0,(a1)+
     bra      EndBin
* Otherwise, set it to a one
DoOne:
     move.b      #1,(a1)+
EndBin:
     dbra      d1,BegBin


     jsr      newline

* Read the binary backwards from a1
     move.l      #8,d1
* Make sure d0 is clean
     clr      d0

*Display BinaryDisplay header
     lea      PutBin,a0
     jsr      strout

     bra      EndBDis
BegBDis:
* Clear d0
     clr.l      d0
* Load the value of a1 into d0
     move.b      -(a1),d0
* Display it
     jsr      decout

EndBDis:
* Checks to see if we've displayed 8 bin values yet
     dbra      d1,BegBDis

     jsr      newline

* Show the ascii header (this would make more sense after the condition,
*  but I didn't invent this!)
     lea      PutChar,a0
     jsr      strout

* If the number is smaller than 0x20 (a control character), don't display
     cmp      #$20,d7
     blt      Begin

     
     lea      AsciiStr,a0
     move.b      d7,(a0)
     jsr      strout



     bra      Begin
* end of processing
Over:
     lea      EOP,a0              address of message
     jsr      newline
     jsr      strout
     break

ShowNums:
*This just outputs d7 and d6 in readable format (for debugging)
     move.l      d7,d0
     jsr      decout
     jsr      newline
     move.l      d6,d0
     jsr      decout
     jsr      newline
     rts
***********************************************************************
IDBanner  dc.b      'NAME               iago',cr,lf
         dc.b      'STUDENT NUMBER     666',cr,lf
         dc.b      'COURSE             74.222',cr,lf
         dc.b      'INSTRUCTOR         Sara',cr,lf
         dc.b      'ASSIGNMENT 2',cr,lf
         dc.b      'QUESTION 3',cr,lf,lf
         dc.b      null                Banner string terminator
EOP       dc.b      'END OF PROCESSING',cr,lf,null
HexStr    dc.w      '    '
       dc.b      null
AsciiStr  dc.b      null      
       dc.b      null                Make sure ascii is null-terminated
BinStr    dc.l      '        '
       dc.b      null
GetHex    dc.b      'Enter a 2-digit (1 byte) hex value: ',null
PutDec    dc.b      'Decimal value: ',null
PutBin    dc.b      'Binary value: ',null
PutChar   dc.b      'Character: ',null


***********************************************************************
         end[/code]
February 15, 2003, 12:39 PM
vile
Nice
January 26, 2004, 12:49 AM
iago
in 20 days, this post will be a year old.
January 26, 2004, 2:39 AM
vile
lol
January 26, 2004, 12:27 PM
Skywing
That would be a hint to stop posting in old topics, particularly if you have nothing useful to contribute.
January 26, 2004, 1:11 PM
Adron
It could also be a threat - stop or be banned.
January 26, 2004, 5:00 PM
iago
[quote author=Adron link=board=7;threadid=380;start=0#msg41194 date=1075136425]
It could also be a threat - stop or be banned.
[/quote]

Skywing's response is more of a threat, mine's a hint :)
January 27, 2004, 12:09 AM
zorm
I really don't see what the big deal with replying to really old posts is? If they make a new post asking question about some random thing that was already talked about but that they don't understand people will tell them to search anyhow. IMHO people complaining that user x bumped an old post are more annoying then anything else.
January 27, 2004, 6:53 AM
iago
[quote author=Zorm link=board=7;threadid=380;start=0#msg41298 date=1075186396]
I really don't see what the big deal with replying to really old posts is? If they make a new post asking question about some random thing that was already talked about but that they don't understand people will tell them to search anyhow. IMHO people complaining that user x bumped an old post are more annoying then anything else.
[/quote]

It's all right if somebody actually has something useful to say, in my opinion.
January 27, 2004, 12:40 PM
Skywing
[quote author=Zorm link=board=7;threadid=380;start=0#msg41298 date=1075186396]
I really don't see what the big deal with replying to really old posts is? If they make a new post asking question about some random thing that was already talked about but that they don't understand people will tell them to search anyhow. IMHO people complaining that user x bumped an old post are more annoying then anything else.
[/quote]This as known as "spam", typically something which results in wasted time due to rereading topics you've already read.

If you want to discuss this further, please take the discussion to at least a different forum.
January 27, 2004, 1:11 PM
Adron
Making useless posts (I.e. "me too" style posts, laughs, or just agreements where noone has disagreed) is acceptable for fresh topics, and where there aren't too many useless posts already. It then adds some measure of feel to the post, kind of like laughing at a joke.

It's unacceptable to make useless posts to old topics, or topics that are getting drowned in useless posts. It's as annoying as people who suddenly start laughing like crazy at a joke you pulled 15 minutes ago, long after the conversation moved on, because they finally understood it.
January 27, 2004, 6:12 PM
iago
[quote author=Adron link=board=7;threadid=380;start=0#msg41342 date=1075227167]
It's as annoying as people who suddenly start laughing like crazy at a joke you pulled 15 minutes ago, long after the conversation moved on, because they finally understood it.
[/quote]

haha, I did that on the weekend. There was a cleverly named something-or-other, and I've known about it for a long time but didn't recognize the pun. Then somebody said it and it clicked and I said, while everybody was dumbly staring at me, "oooh I get it now! HAH!" If I remember what the pun was, I'll share it :)
January 27, 2004, 6:45 PM
St0rm.iD
year old tomorrow!
February 14, 2004, 11:01 PM

Search