Continue to Site

# Microcontroller in assembly language

#### Mina2016

##### Junior Member level 1
Hello. In MDK KEIL, I created a simple c program and then I need to read data in Hex from the memory(STM32).
in C program I have
short b=255
int c=256
I know that in 8 bit numbers, the max number is 255. I wonder if the two line of the program above are correct or not. If so, how I can convert those to hex.

#### Attachments

710.9 KB · Views: 101

Hi,

You ask if both lines are correct? In which regard correct (or not correct)?

You ask how to convert in HEX. Why? I mean HEX, decimal, binary are all just ways to represent numbers.
0xFF = 255 = 0b11111111 ... no need to convert them.

Klaus

Hi,

You ask if both lines are correct? In which regard correct (or not correct)?

You ask how to convert in HEX. Why? I mean HEX, decimal, binary are all just ways to represent numbers.
0xFF = 255 = 0b11111111 ... no need to convert them.

Klaus
--- Updated ---

I meant how to represent 256 in hex with 8bits.

the largest number you can represent with 8 bits is 255 (0b11111111)
or, in hex, 0xFF
while there are 256 number, they are 0 to 255.

the largest number you can represent with 8 bits is 255 (0b11111111)
or, in hex, 0xFF
while there are 256 number, they are 0 to 255.
--- Updated ---

Doesn’t the number 00000100(in hex) equal to 256 in decimal?

Yes.

Regards, Dana.

Hi,

I meant how to represent 256 in hex with 8bits.
256 doesn't fit in 8 bits. 256 = 0x100 ... but 3 full hex nibbles need 12 bits.
An "int" variable isn't necessarily 8 bits. It depends on microcontroller and compiler.

So you asked for the info "256 = 0x100". I wonder, becase many handheld calculators, cellular phones, every PC can do this, also there are web sites.

Klaus

Hi,

256 doesn't fit in 8 bits. 256 = 0x100 ... but 3 full hex nibbles need 12 bits.
An "int" variable isn't necessarily 8 bits. It depends on microcontroller and compiler.

So you asked for the info "256 = 0x100". I wonder, becase many handheld calculators, cellular phones, every PC can do this, also there are web sites.

Klaus
I have attached a file to my post which includes c program. At the bottom of that file, there is a memory address with data in hex. I need to show how numerical and nunnumerical data is stored in memory. That is why I asked what 256 is in hex(with8bits) because I wanted to find hex representation of it in the memory. I attach that file here again. I also have identified two numbers of 255 and 256 in hex . Could you take a look at it and let me know what you think? tnx.
--- Updated ---

I have attached a file to my post which includes c program. At the bottom of that file, there is a memory address with data in hex. I need to show how numerical and nunnumerical data is stored in memory. That is why I asked what 256 is in hex(with8bits) because I wanted to find hex representation of it in the memory. I attach that file here again. I also have identified two numbers of 255 and 256 in hex . Could you take a look at it and let me know what you think? tnx.
this the file

#### Attachments

• A3A4AAB6-0CF2-49B8-936A-A57C9D6DFDC9.jpeg
778 KB · Views: 83

In C compilers have some different sizes for some of their data definitions.
So you need to look at the compiler header files or manual for the definition
of what size type, and name applies.

Regards, Dana.

STM32 is 32 bit processor, int has 32 bit (4 byte) size, short 16 bit (2 byte). To avoid problems with target dependent data sizes, portable projects use unique type names like int32t, int16t, int8t and uint32t, uin16t, uint8t.

Last edited:

Hello!
I have attached a file to my post which includes c program. At the bottom of that file, there is a memory
address with data in hex. I need to show how numerical and nunnumerical data is stored in memory. That
is why I asked what 256 is in hex(with8bits) because I wanted to find hex representation of it in the memory.
I attach that file here again. I also have identified two numbers of 255 and 256 in hex . Could you take a
look at it and let me know what you think? tnx.

All your variables are in the memory.
61 62 63 64 at the beginning of your line is abcd
41 42 43 44 later is ABCD
30 31 32 33 is 0123
and the separators (space) are the 20 between the alphanumeric groups.
What's the problem?

Dora.

All your variables are in the memory.
61 62 63 64 at the beginning of your line is abcd
41 42 43 44 later is ABCD
30 31 32 33 is 0123
and the separators (space) are the 20 between the alphanumeric groups.
What's the problem?
OP is specifically asking for memory representation of the numerical variables. The posted sketch is however incorrect.
- short has 16-Bit size
- ARM processor is using little endian number format, least-significant byte at the smallest address.

Respectively the correct annotation looks like this

You may also find this write-up helpful.