javierdemartin
javierdemartin

Reputation: 645

How to divide a number stored in a variable by a number

I have a number stored in the position 30 and I want to divide it by 10. When I try to do so it gets the value of the register it is in instead of the value stored in the position.

HDUTY    EQU    30

MOVLW    D'46'
MOVWF    HDUTY

MOVLW    (HDUTY / 10)
ADDLW    '0'           ; Transform value to ASCII
CALL     LCDDWR        ; Call function to display on LCD

What I should see on the W register is 4 as 46/10 ≈ 4, but I see a 3 as of the number of the position the HDUTY variable is. If I change the variable to the position 50, I see as a result a 5 instead of a 4. How should I do a division of the number stored in a variable by a number?

Upvotes: 0

Views: 130

Answers (2)

cup
cup

Reputation: 8267

The default PIC numeric base is hexadecimal - the 10 is actually 16. Since 46/16 ≈ 3, you get 3 after adding '0'.

Upvotes: 0

Jacob Krall
Jacob Krall

Reputation: 28835

The format of a statement in assembly looks like this:

OPERATION   ARGUMENT (...ARGUMENTS)

Assembly is the second lowest-level programming language there is. Any calculation that happens in the argument will happen at assembler time, not at run time.

Calculations that are done at run time must be specified by you, as an operation or series of operations.

Your PIC probably does not have a division opcode, so you will have to write a division procedure yourself.

Upvotes: 1

Related Questions