Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

hex question

Status
Not open for further replies.

Ambient

New Member
This is probably a dumb question, but I could not find a reasonable explanation after hours of searching. When do I use 0x prefix and when do I use 0000h? I keep seeing both appear in the same program, and all the tutorials I can find do not explain the difference. I know both are hex. I mostly see the 0x prefix for addresses, but have also seen it in variable declarations. Can someone clear up my confusion?
 
Thanks. I just wasn't sure if MPLAB needed a specific form of hex label for the instructions to work.
 
If you are confusing with the hex numbers
Let say you want to move DECIMAL 50 to PORTB. But you don’t know what’s the exact HEX value for decimal 50.

Then you can write

Code:
	Movlw D.50
	Movwf PORTB
But the actual HEX value for DECIMAL 50 is 32h.

3 X 16 + 2 = 50

MPLAB Text Editor is a powerful tool it detects any number in any manner which you input it by DECIMAL, HEX, BINARY etc…

For more information about the hex number system go through this link.

**broken link removed**
 
Last edited:
The two methods of representing a hexadecimal constants come from different origins. The 'h' suffix was popular in assemblers for intel microprocessors in the early 1970s. The assemblers for the 8008, 8080, and 8085 all had this feature. The 0x notation appears to have made its appearence with the K&R C compiler in the late 1970's. Since that time many assembler writers have made both forms of expression acceptable since we no longer have the memory limitations of the early 1970s. Curiously the compiler writers do not seem to have returned the favor. I guess we can chalk that up to standards committees.
 
Gayan Soyza said:
If you are confusing with the hex numbers
Let say you want to move DECIMAL 50 to PORTB. But you don’t know what’s the exact HEX value for decimal 50.

Then you can write

Code:
	Movlw D.50
	Movwf PORTB

I thought decimal 50 could be either .50 or d'50' not d.50.


Mike.
 
The various different number formats are explained in the MPASM/MPLAB help file, to make the assembler as versatile as possible, it accepts HEX in a number of different styles - as suggested, these vary according to your programming heritage.
 
Status
Not open for further replies.

Latest threads

Back
Top