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.

Really basic PIC question

Status
Not open for further replies.

Froskoy

New Member
Hi,

I'm just starting out with PIC and am reading a couple of books.

Just one thing that I've been searching around to try and find an answer for and can't - wondered if anyone could help?

OK so normally with hexadecimal I'd just write F0 to represent 11110000.

So why in the instruction
Code:
movlw 0xF0
is the 0x bit in there if I wanted to move the number F0 into the working register.

Also why do the books supersede the F0 with an 'h' to make F0h?

Sorry for probably being a noob but these are issues I'd really like to sort out early on.

Thanks very much,

Froskoy.
 
I"ve seen that too , it means all the same I think " movlw 0xF0h "

If the compiler compiles the instruction , than it's alright
 
Last edited:
'0x' tells the assembler that it is hex, as does h'07'.
It's just that there are various different ways to do the same thing.
 
Hi,

0xF0 is just one of the ways to let the complier know that the value F0 is in hex.

Typical case would be 12 - is that number in hex, decimal, octal, ascii etc etc ?

When you start programming some code in a 'project' the system will have a default Radix setting so any number you code without clear indication is automatically assumed to be the type held by the default Radix.
 
At a guess, where no radix is specified in the listing, it makes it easy to spot which type is being used at a glance, but also makes it perfectly clear to the compiler.

Binary is pretty easy to spot and hex is also easy to spot when A to F are used, but without anything to provide clarification there can be some confusion.

IIRC, MPASM assumes you are using hex until you specify otherwise.

Consider the use of 10 as a value.

Without any specific information as to the correct radix used, MPASM sees it as 10 in hex, which is 16 in decimal. If you actually meant 10 in decimal.....

Sometimes, programmers will list the radix used at the top of a listing.... "list r=dec" or "radix dec" "radix hex" or something else.... other times they will not and that is where the 'extra' info helps.

I'm quite sure that others will add to this and also correct any errors I may have made, but I hope this helps you.

EDIT: Other posts were made whilst composing this...
 
Last edited:
Any mixture of binary, Hex and decimal numbers can be shown in a program.
Binary numbers are presented as: 0b'00000000' or b'00000000' or B'00000000' or 00000000b or b'0100' to indicate the lowest 4 bits.
Hex numbers are shown as: 0x2 or 0x0F (= fifteen) or 0x3C or h' or $ ($F or $f or $3A or $0ff )
or <digits>h (must begin with 0 ....9) examples: 80h 3Ah 0FFh or 0ffh (do not put ffh or FFh as the compiler requires 0 to 9 at beginning)
Decimal numbers are shown as: d'250'
or decimal numbers without a prefix. They can also be written with a decimal point. examples: .250 .80 .100
 
Status
Not open for further replies.

Latest threads

Back
Top