I understand, in microcontrollers assembly language is converted to binary by the assembler. To my understanding, it is a program run on a separate machine. Then the produced machine code is stored on ROM and executed. Is it correct? If so, in the case of a microprocessor trainer kit, who executes the assembler code?
Asked
Active
Viewed 60 times
0
-
For microcontrollers, usually you use a separate more-capable machine to run the assembler (one with a disk and other I/O, especially one you can connect an EEPROM programmer to.) In general, for a new CPU, you use an existing system, but yes the very first assemblers were hand-written in machine code. [How was the first assembler for a new home computer platform written?](https://retrocomputing.stackexchange.com/q/3326) / [how do they used to enter machine code directly in olden days?](https://stackoverflow.com/q/3167914) – Peter Cordes Jan 04 '23 at 07:00
-
*who executes the assembler code?* - nothing executes assembly code directly, only machine code. Even a simulator would normally assemble to a binary and simulate a microcontroller executing that. That part could be a duplicate of [How does hardware run assembly? How was the first assembler written?](https://stackoverflow.com/q/12007435). But actually it's already answered by the start of the answer on the first duplicate, [How does assembly code actually get interpreted at the basic level?](https://stackoverflow.com/q/49489376) – Peter Cordes Jan 04 '23 at 08:37
-
Various other Q&As explaining that CPUs don't execute assembly language text include [How do assembly languages work?](https://stackoverflow.com/q/6463938) / [How do instructions from a program get sent to different memory levels? Are they pre-loaded when the chips are manufactured for the first time?](https://stackoverflow.com/q/71009573) / [How does assembly code get compiled and run?](https://stackoverflow.com/q/73159895) – Peter Cordes Jan 04 '23 at 08:41
-
I only skimmed those other questions, so maybe none of them go into as much detail as I hoped on that point. In a development kit, you might also have remote debugging (e.g. JTAG I think) to let the dev machine single-step the microcontroller, in which case it's still the microcontroller running the machine code (not the assembly text directly). There are probably other Q&As about that, if that's the answer you're looking for. – Peter Cordes Jan 04 '23 at 08:45
-
Thanks, but my actual question is, if I write a program in assembly language, it should be converted into machine code and must be stored in ROM, right? We have an assembler to do that, and the assembler runs on another machine. If we take an 8051 microprocessor trainer kit, for example, we input code in assembly language, so there must be an assembler in the kit. If so, don't we need an additional processor to execute the assembler code or is it done by the 8051 itself? Am I missing something? – The Dumb Coder Jan 04 '23 at 08:51
-
What is a "trainer kit" exactly? A board with an 8051 on it, and some software for another machine? With enough RAM and ROM, an 8051 could run an assembler itself, but that's not how you'd normally develop for any microcontroller. You'd want a general purpose computer with a keyboard for editing the asm, so you also run the assembler (and linker) there. – Peter Cordes Jan 04 '23 at 09:08
-
If it's something like an early 8-bit microcomputer sold for home usage in the early 80s, then yeah it probably has an assembler in ROM, assembling a program into RAM. [How was the first assembler for a new home computer platform written?](https://retrocomputing.stackexchange.com/q/3326) is about how those IDE+assembler programs were created for those computers, but comments under that retrocomputing question discuss what kind of software those assemblers were. (If it's not a full IDE, you might call it a "monitor", like on very early computers too small for an OS.) – Peter Cordes Jan 04 '23 at 09:15
-
1by trainer kit, I mean a board with 8051 on it, connected to a keyboard and a display. something like this https://www.vimicrosystems.com/assets/php/products/Microprocessor%20&%20Controller/photos/89c51.png and we can input and run different programs written in assembly language. It does not use any other computers. So each time we input a new program, it must be converted into machine code by the assembler. in this case, don't we need a separate processor onboard to run the assembler? – The Dumb Coder Jan 04 '23 at 09:21
-
No, if the CPU (or MCU) can execute machine code from RAM, it can read text and store machine code into RAM, then later execute that machine code. What you're describing is the same thing as classic 8-bit micros with an assembler program that included a text editor. Or like a desktop running a text editor and assembler to generate executables for itself. You just normally don't do that with an 8051 because normally you'd only equip it with a tiny amount of RAM for real MCU use-cases, unlike your "trainer". – Peter Cordes Jan 04 '23 at 09:34
-
So in the classic 8-bit micros and my "trainer", The assembler is stored in the ROM and it is executed by the 8051(onboard processor) itself? – The Dumb Coder Jan 04 '23 at 09:51
-
Yes for classic 8-bit micros, and I assume for for your 8051 trainer kit. With the keyboard input right on the exposed board, they probably do that instead of having a separate CPU handling I/O. Actually, for classic 8-bit micros, the assembler was a program you could load from a floppy or tape or whatever, so it would run from RAM as well. Unless you had one in a ROM cartridge. – Peter Cordes Jan 04 '23 at 10:10
-
Well it depends on the implementation of the 8-bit micro. Many home computers of the era had programs that came on a floppy disk. Back in the day those programs had to load, and it would take a few minutes. The program was copied from the floppy disk to the computer's RAM and then executed from the computer's RAM. However, not all machines back in the day did that. The Nintendo Entertainment System used a ROM cartridge which was instantly mapped into the CPU's address space, no loading required. As soon as you pressed the power button it's like the program code was there all along. – puppydrum64 Jan 04 '23 at 13:35
-
If you want to tell if memory is RAM or ROM try writing a value to that memory and reading it back, if you get the same result both times, it's most likely RAM. – puppydrum64 Jan 04 '23 at 13:37
-
In general, there can be exceptions. For an MCU. Software development (assembly language or other) is done on a development computer, your desktop/laptop. Yes a binary including machine code is generated. Through some mechanism, hardware and software, that binary is loaded into some storage tied to the mcu processor, that can be volatile or non-volatile (ram or flash/rom) depending on the design, some may allow for both options. Then the mcu processor itself runs that code. – old_timer Jan 04 '23 at 16:30
-
8051s in particular are still actively being used, cheap/free, no license. Between me typing this on my computer and SO and then to you reading on your computer many to dozen/hundreds of 8051s were involved, most of which run from ram, the ram is loaded from somewhere be it the /lib/firmware dir on the operating system a flash on the board that logic or software uses (but not directly tied to the 8051). a typical mcu will use flash for non-volatile storage and that flash is connected such the mcu processor can boot and execute code directly from it, that is the typical use case. – old_timer Jan 04 '23 at 16:33
-
8051s in particular have been so massively cloned that there is not one answer. If you look at say an msp430 which is for the most part controlled by one vendor or the avr or pic, then it is either a flash or one time programmable rom, in general. arm and soon to be risc-v cores are purchased ip that any vendor can buy and put in their chip, the chip vendor determines what the processor core is hooked to not the processor core company, so similar to the 8051 the answer as to ram/rom varies, but end of the day the mcu processor executes the mcu code, and development is done elsewhere. – old_timer Jan 04 '23 at 16:36
-
if you remotely care or if part of the question, go far enough back, say the kim-1 fo 6502 or the pdp family (not mcus but full on computers, the 6502 at this time was not an mcu either really). these were ram based (well....okay....core memory is non-volatile-ish) and the user would manually using buttons or switches input the machine code and data to at least a point where the processor could run enough code to read from some other device. and some percentage of that code was developed with pencil and paper and not on another computer. kim-1 was a "kit". – old_timer Jan 04 '23 at 16:45
-
In the case of kim-1, the 'firmware' is stored in two ROM chips. Is the firmware contains the assembler code? (or whatever program that converts the input into machine code) – The Dumb Coder Jan 04 '23 at 17:00
-
The assembler probably exists on the computer you're using right now, and it copies the binary executable to a EEPROM chip – puppydrum64 Jan 05 '23 at 11:30