Thread: Need Help with Assembly

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    10

    Need Help with Assembly

    This program is supposed to count the number of letters in a string

    Code:
                ORG RAMStart
    
    String      DC.B  "This is a test string",0
    Size         DS.B  1      
          
          
    
    
    ; code section
                ORG   ROMStart
    Entry:
                        
      LDX        #String
      LDAA      #0
      
    loop:   
      LDAA      0,x
      inc          Size
      inx
      bne       loop
      bra       *
    I figured when the null character was loaded into accumulator A that it would end the loop, but it keeps counting the size. Any ideas as to how to solve this. Also, is there a board similar to this for assembly? Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Not a C question, moved.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    10
    Well why don't you make an assembly sub forum. No one reads this Tech board apparently.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Because this is C programming.com.
    We don't have asm for the same reason we don't have pascal, cobol or fortran sub-sections either.

    Try daniweb, they have an asm forum there.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well first of all, its not my fault that people use similar titled threads in the Tech forum and you just assume its the same old answered question.

    Secondly, I am only familiar enough with SPARC assembler to identify it. So excuse me for only knowing how to write assembler for a modern piece of hardware.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need a BEQ (and possibly a compare with zero - I don't know the assembler well enough, but most assembler languages will set the zero flag ) after you load the character from the string into AA. AA is overwritten as soon as you load the first character from the string, so storing zero in it will not make any difference.

    [I have no idea which processor this is for - perhaps one of those funny 6502-extensions that Hitachi have been making for quite a few years, e.g. HC11 or HC12]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Most assemblers offer an opcode that jumps only when the zero flag is set. For SPARC assembler I believe "bz" is the appropriate opcode. So swap out your bne with bz and increment the original string pointer and check its value against zero.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    BNE and BZ are nto the same thing. BNE is BNZ. BZ is BE or BEQ depending ont eh assembler used..

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If I am not mistaken, BNE is Branch if Not Equal. So your loop will exhibit funky behavior...

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by master5001 View Post
    If I am not mistaken, BNE is Branch if Not Equal. So your loop will exhibit funky behavior...
    I'm sure that a BNE in that place would be perfectly fine _IF_ the Z flag was set by the LDAA, but it's (probably) also set by both of the next two instructions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    It don't think INX will change the z flag. But I am not sure. INC definitely should modify the z flag. I would still have the last thing done proir to jumping be to do a comparison. That is a more conventional way of doing this sort of thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Assembly
    By mrafcho001 in forum Tech Board
    Replies: 5
    Last Post: 03-12-2006, 05:00 PM
  2. C to assembly interface
    By Roaring_Tiger in forum C Programming
    Replies: 4
    Last Post: 02-04-2005, 03:51 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM