Programming from scratch

nsaspook

Joined Aug 27, 2009
16,326
You can, and most of the time it will work, but the C language standard says it is implementation defined. That is why I say you cannot do it with standard C.
Standard C, it's just a pedantic distinction with no practical importance on the subject of absolute addressing of variables, registers, and memory in general.

As part of the C standard, you MUST consult each implementation for those delineated Implementation defined details, extensions and attributes for each architecture/CPU instruction set the compiler is designed to be used for. The standard is written so C can be useful and practical on each architecture/CPU instruction set. This is a very good way to write a standard for compilers designed to expose underlying hardware behavior because it's needed in most low-level hardware controller applications.
 

BobTPH

Joined Jun 5, 2013
11,516
Being a compiler developer, I guess I see things a bit differently. I can write a C complier in full compliance with the standard that makes it impossible to access an absolute address.
 

nsaspook

Joined Aug 27, 2009
16,326
Being a compiler developer, I guess I see things a bit differently. I can write a C complier in full compliance with the standard that makes it impossible to access an absolute address.
Almost every person serious about programming has written a compiler or two (using something like YACC) as a personal or school project.
https://en.wikipedia.org/wiki/Yacc#:~:text=Yacc (Yet Another Compiler-Compiler,Johnson.

Then you have a C compiler that's mainly useless for low-level hardware embedded programming at the C source level. Why would a compiler developer write such an abomination when great general compilers like GCC make it easy to use absolute addresses? Like I said, totally pedantic and not something you would write as a practical tool. Have you actually written a C compiler like that? You can peek and poke addresses in Basic.
 
Last edited:

BobTPH

Joined Jun 5, 2013
11,516
Why would a compiler developer write such an abomination when great general compilers like GCC make it easy to use absolute addresses?
I didn’t say I would! I said I could.

A compiler for Windows programming would offer no benefit by allowing access to the absolute addresses. I am not going to look it up, but I expect Microsoft Visual C++ does not offer it.

I have already proven that your statement about absolute addresses in a standard C is false. I will say nothing further.
 

eetech00

Joined Jun 8, 2013
4,705
I'm not certain if my question makes complete sense, but I have a curiosity regarding program. assume we have datasheets of microcontroller contain information about various ports like Port 1, Port 2, Port 3, and Port 4, along with their respective memory addresses. 0x01, 0x02, 0x03 and 0x04

Let's assume we have a compiler installed on our system, and the task at hand is to write a small C program that sets the 7th bit of Port 1. Now, here's the twist: let's assume this is a new microcontroller developed , and we're writing code for it for the first time.

How should I go about writing this C program entirely from scratch by examining the datasheet to accomplish this task?

I want to clarify that this isn't a homework assignment or a time-bound task assigned by someone; it's a personal curiosity aand thought I'm sharing with you
I think what your really asking how to structure the MCU program using embedded C.

Assuming you know and understand the MCU datasheet info, and "C" for the MCU's compiler, you would:

1. setup MCU configuration
2. initialize MCU inputs/outputs
3. declare functions and includes
4. write main code
 

nsaspook

Joined Aug 27, 2009
16,326
I didn’t say I would! I said I could.

A compiler for Windows programming would offer no benefit by allowing access to the absolute addresses. I am not going to look it up, but I expect Microsoft Visual C++ does not offer it.

I have already proven that your statement about absolute addresses in a standard C is false. I will say nothing further.
Great, so this standard C is false is totally academic (, would strangely make the GCC compiler non-standard) and has nothing to do with actual embedded C compilers usage in this thread or anywhere else

Sure, it's part of standard C that's implementation defined (in the C standard), just like many other things in the C standard that makes C a useful language for embedded programming for each target architecture. As for using Windows software (specifically software not designed for low-level embedded software) as a standard feature set for embedded applications, well, that's why most smart people use Linux instead of Windows.
 
Last edited:
Top