Need Help with Assembly
This program is supposed to count the number of letters in a string
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
String DC.B "This is a test string",0
Size DS.B 1
; code section
Well why don't you make an assembly sub forum. No one reads this Tech board apparently.
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.
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.
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]
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.
BNE and BZ are nto the same thing. BNE is BNZ. BZ is BE or BEQ depending ont eh assembler used..
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.
Originally Posted by master5001
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.