Quantcast

Maximum PC

It is currently Wed Apr 23, 2014 7:59 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Anyone here good with assembly?
PostPosted: Thu Feb 28, 2008 7:46 pm 
Team Member
Team Member

Joined: Mon Jul 25, 2005 4:12 pm
Posts: 1273
Location: AL
I'm working on a HW assignment. I know what the code needs to do, but i'ts not quite bending to my will.

Can anyone comment on this with an idea about what my problem is? I think I know the problem.. but I'm not sure how to fix it.

Code:

ORG RAMStart
           
samples   dc.b    $01,$12,$F0,$33,$C9,$25,$E3,$08
psum      ds.b    1
nsum      ds.b    1
number    dc.b    $08
count     ds.b    1

           
; Insert here your data definition.



; code section
            ORG   ROMStart
Entry:
            ldab  samples
            ldx   number
start:     
           
            ldaa  1,b+
            tsta
            bmi   minus
            bpl   plus
           
           
           
minus:
            adda  nsum
            staa  nsum
           
            dex
            tst   #number
           
            bne   start
            bra   stop
           
           
plus:       
            adda  psum
            staa  psum
           
            dex
            tst   #number
           
            bne   start
            bra   stop
           
stop:
           
           
            RTS                   




Top
  Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 8:15 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
What is it supposed to do?
What does it do?
What do you think the problem is?


Top
  Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 8:20 pm 
Team Member
Team Member

Joined: Mon Jul 25, 2005 4:12 pm
Posts: 1273
Location: AL
Supposed to do:

The array sample contains 8 8-bit signed binary numbers (integers) as shown below. Write a
program which computes the sum of non-negative numbers and the sum of negative numbers, and
stores them psum and nsum, respectively. Your program should work for any 8 numbers
stored in samples. RAMStart=$0800 and ROMStart=$4000.
samples DC.B $01,$12,$F0,$33,$C9,$25,$E3,$08
psum DS.B 1
nsum DS.B 1

what does it do:
Not what it is supposed to. It only loops into the plus branch....

Problem:
not sure why it is doing this.

Updated Code:

Code:

ORG RAMStart
           
samples   dc.b    $01,$12,$F0,$33,$C9,$25,$E3,$08
psum      ds.b    1
nsum      ds.b    1
number    dc.b    $08


           
; Insert here your data definition.



; code section
            ORG   ROMStart
Entry:
            ldab  number
            ldx #samples
start:     
           
            ldaa  1,x-
            tsta
            bmi   minus
            bpl   plus
           
           
           
minus:
            adda  nsum
            staa  nsum
           
            decb
            tstb
           
            bne   start
            bra   stop
           
           
plus:       
            adda  psum
            staa  psum
           
            decb
            tstb
           
            bne   start
            bra   stop
           
stop:
           
           
            RTS                   


Top
  Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 8:47 pm 
King of All Voodoo2 Cards
King of All Voodoo2 Cards
User avatar

Joined: Tue Jun 22, 2004 10:41 am
Posts: 9316
This code looks like it might have been designed for a micron. I'm guessing some flavor of Intel 8051.

Is it?


Top
  Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 9:02 pm 
Team Member
Team Member

Joined: Mon Jul 25, 2005 4:12 pm
Posts: 1273
Location: AL
Nope, for a motorolla(freescale) HCS12 series

I got it working.. I had a post decrement when I needed a Post increment

Code:

ROMStart    EQU  $4000  ; absolute address to place my code/constant data
RAMStart    EQU  $0800
; variable/data section

            ORG RAMStart
           
samples   dc.b    $01,$12,$F0,$33,$C9,$25,$E3,$08
psum      ds.b    1
nsum      ds.b    1
number    dc.b    $08


           
; Insert here your data definition.



; code section
            ORG   ROMStart
Entry:
            ldab  number
            ldx #samples
start:     
           
            ldaa  1,x+
            tsta
           
            bmi   minus
            bpl   plus
           
           
           
minus:
            adda  nsum
            staa  nsum
           
            decb
            tstb
           
            bne   start
            bra   stop
           
           
plus:       
            adda  psum
            staa  psum
           
            decb
            tstb
           
            bne   start
            bra   stop
           
stop:
           
           
            RTS   



Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 6:01 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I wasn't sure. I "know" Intel assembly and that didn't look like it to me :)


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

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group