Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code is taking input rather than printing a character count for the letters

<pre>     
        .global _start

_start:
        LDR R1, =test_string
        MOV R2,#0

nextw:
            LDR R3,[R1]
            MOV R5, #4

nextb:
            MOV R4, R3
            AND R4, #MASK
            CMP R4, #EOS
            BEQ arrayloop
            BL array

            ADD R2, #1
            SUB R5, #1
            CMP R5, #0
            BEQ incr
            LSR R3, #8
            B nextb

incr:
            ADD R1,#4
            B nextw
        
array:
            LDR R2, =freq
            MOV R3, #4
            MUL R4, R3
            ADD R4, R1
            LDR R3, [R1]
            ADD R3, #0X01
            STR R3, [R1 ]
            BX LR
        
        make10s:
	LDR R0, =tens 
	MOV R1, #10   
	MOV R2, #1    
	MOV R3, #10   

arrayloop:
         LDR R1, =freq
         MOV R6, #0x00
         BL make10s

actualloop:
        CMP R6, #128 @ASCI value upto 127
        BEQ _exit
        LDR R0, [R1]
        BL printd
        ADD R4, #0x04
        ADD R6, #0x01 @Add one to index 
        B actualloop

pow10:
        STR R2, [R0] 
	SUB R1, #1   
	CMP R1, #0   
	BEQ done10
	ADD R0, #4   
	MUL R2, R3   
	B pow10

done10:
        BX LR
        
printd:
        MOV R1, #10
	LDR R2, =tens 
	ADD R2, #36
        
nextchar:
	LDR R3, [R2]
	MOV R4, #0   

loop10:
        CMP R0, R3    
	BLT showd
	SUB R0, R3
	ADD R4, #1
	B loop10

showd:
        ADD R4, #'0'
        
	LDR R5, =char
	STR R4, [R5]

	PUSH {R0}      
	PUSH {R1}
	PUSH {R2}

      
	MOV R0, #1    
	LDR R1, =char  
	MOV R2, #1     
	PUSH {LR}      
	BL write       

      
	POP {LR}       
	POP {R2}
	POP {R1}
	POP {R0}

next10: 
        SUB R1, #1  
	CMP R1, #0  
	BEQ nl
	SUB R2, #4  
	B nextchar
        
endp:
        BX LR

write:
        MOV R7, #4
	SWI 0
	BX LR

nl:    
        MOV R0, #1  
	LDR R1, =nls 
	MOV R2, #1  
	PUSH {LR}    
	BL write    
	POP {LR}    
	BX LR        


_exit:	MOV R7, #1
	MOV R0, #0
	SWI 0

freq:	.rept 128
	.word 0x00 @ initialise character counts as 0
	.endr
.data
.equ O_RDONLY, 0x0000
char:	.word 0x00

nls: 	.word '\n'
sps:	.word ' '


tens:	.rept 10
	.word 0x00
	.endr



.data
.equ MASK, 0x000000ff
.equ EOS, 0

next:	.word 0x00  
count:  .word 0x00  
test_string:   .asciz "coooow"


What I have tried:

No clue what changes to make, any help is appreciated
Posted
Updated 4-Mar-21 4:04am
v3
Comments
Richard Deeming 5-Mar-21 5:47am    
Removing the content of your question after others have tried to help you is extremely rude.

I have reverted your destructive edit.

Quote:
Code isnt working as expected


Well ... that's normal. Writing code that compiles - or in this case assembles - correctly, does not mean your code is right!

Compiling does not mean your code is right! :laugh:
Think of the development process as writing an email: compiling / assembling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it.

Once you have an idea what might be going wrong, start debugging to find out why.

If you have debug facilities (JTAG / whatever) then use it: Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?

If you don't, then fall back on older methods: add logging code to show you where it got to and what it was looking at.

Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
 
Share this answer
 
Quote:
Code isnt working as expected

I don't know ARM assembler, but I know this kind of problem.
I t is probably time to launch the debugger.
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

The downside of this solution:
- It is a DIY, you are the one tracking the problem and finding its roots, which lead to the solution.
The upside of this solution:
- It is also a great learning tool because it show you reality and you can see which expectation match reality.

secondary effects
- Your will be proud of finding bugs yourself.
- Your learning skills will improve.

You should find pretty quickly what is wrong.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900