Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Microcontroller in assembly language

Mina2016

Junior Member level 1
Junior Member level 1
Joined
Oct 23, 2022
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
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.
Tnx in advance.
 

Attachments

  • 8EB920FB-D8AD-46F8-8581-D617776A9003.jpeg
    8EB920FB-D8AD-46F8-8581-D617776A9003.jpeg
    710.9 KB · Views: 41

KlausST

Super Moderator
Staff member
Advanced Member level 7
Joined
Apr 17, 2014
Messages
23,263
Helped
4,741
Reputation
9,503
Reaction score
5,126
Trophy points
1,393
Activity points
154,109
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
 

Mina2016

Junior Member level 1
Junior Member level 1
Joined
Oct 23, 2022
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
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.
 

wwfeldman

Advanced Member level 4
Advanced Member level 4
Joined
Jan 25, 2019
Messages
1,064
Helped
224
Reputation
447
Reaction score
285
Trophy points
83
Activity points
8,131
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.
 

Mina2016

Junior Member level 1
Junior Member level 1
Joined
Oct 23, 2022
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
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?
 

KlausST

Super Moderator
Staff member
Advanced Member level 7
Joined
Apr 17, 2014
Messages
23,263
Helped
4,741
Reputation
9,503
Reaction score
5,126
Trophy points
1,393
Activity points
154,109
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
 

Mina2016

Junior Member level 1
Junior Member level 1
Joined
Oct 23, 2022
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
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
    A3A4AAB6-0CF2-49B8-936A-A57C9D6DFDC9.jpeg
    778 KB · Views: 24

danadakk

Advanced Member level 5
Advanced Member level 5
Joined
Mar 26, 2018
Messages
2,296
Helped
351
Reputation
720
Reaction score
529
Trophy points
113
Activity points
10,092
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.
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
50,989
Helped
14,631
Reputation
29,538
Reaction score
13,740
Trophy points
1,393
Location
Bochum, Germany
Activity points
291,735
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:

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top