0
$\begingroup$

Update: To clarify. MyNOR (http://mynor.org/) stores some combined instructions in ROM to make programs take up less space. It seems very possible that instruction sets for CPUs might do similar, in more normal computers. I was interested if such load as part of some operative system/kernel/whatever it is called, or is at lower level and seen as "hardware" (if it tends to exist. )

I've learnt basic computer architecture over the past years, and now want to learn about the lowest level of software. I've understood from https://nandgame.com that instructions are not only machine instructions in hardware (such as activating a multiplexer or such), but also combinations of instructions that allow for some of the basic OPCODEs (that are really combinations of instructions. ) Nandgame calls these "assembly macros". I was interested in if these are normally loaded in relatively early in a computer, or if low level processes (bootloader, BIOS, kernel, shell) do not make use of "assembly macros" (or whatever they are called. ) In general, there are many standard trends, but I am interested in all of computer science and engineering history too incl. mainframes in 1950s and what not.

$\endgroup$
2
  • $\begingroup$ A copy of Nandgame's definition and a more specific hyperlink would help. (came up empty in a quick search) $\endgroup$
    – greybeard
    Sep 8, 2022 at 8:39
  • $\begingroup$ Nandgame used the term "stack-operation macros". Here they are, created with the machine instructions, i.imgur.com/i7NYhDh.png. And in the MyNOR computer, the guy had a ROM with the "macros" that loaded in before any of his other programs. I assume the instruction set of a CPU tends to include some "software macros" for some basic operations (unless everything is "mechanical" but some seem like they would be combinations of the basic ones) and that it might be more seen as the hardware level than operative system or anything. $\endgroup$
    – BipedalJoe
    Sep 8, 2022 at 16:49

2 Answers 2

2
$\begingroup$

Unfortunately the site you have been looking at has confused you by using the word "instructions" to mean two different things.

A machine instruction tells the machine to do something. For instance, on the Intel 8080 the instruction with byte value 3E says "Read the byte after this, and store it in the A register".

In assembly terms this is MVI A,xx – where "xx" is a number. It is convenient to call this "an assembly language instruction", but this is not really an instruction. It is the letter M followed by the letter V followed by the letter I and so on, and it is the job of the assembler (a program) to read those letters and output the byte 3E followed by a byte containing the number "xx".

No machine executes assembly language instructions. Machines execute machine instructions: that is, they look at a byte in memory (identified by the program counter) and perform - in hardware - whatever action the designer have decided should be performed when that byte is seen. In the example I have given this is: add 1 to the program counter, read the byte in memory which is identified by the program counter and store it into the A register, add 1 to the program counter.

An assembly language instruction is generally translated, by the assembler, into a byte or sequence of bytes which make up one single machine instruction. Thus in the example I have given, "MVI A,7" would be translated into "3E 07".

Sometimes it is more convenient for the programmer if one programmer-written instruction performed an operation that takes more than one machine instruction. For instance, the 8080 can only add numbers to the A register and not to any of the others. Suppose that you find yourself wanting to add a number to the C register, not the A register. Then you would have to move C to A (MOV C,A), add the number to A, (ADI xx), and move the result to C (MOV A,C). Moreover, you would not want the value of A to be changed by this, so you might want to save A beforehand (PUSH PSW) and restore it afterwards (POP PSW).

You wouldn't want to be writing such a long sequence of instructions every time. It is not only tedious, it is error-prone. What you would like is to have a new "instruction" which looks something like "ADIC xx" and which gets translated to the sequence of machine instructions which will save A, move C to A, add xx to C, move A to C, and restore A.

That is what a macro invocation is. It is like inventing a new instruction. When you specify it to the assembler you will normally specify it as "When you see this new instruction, process the following assembly instructions" - which in this case would result in emitting the five machine instructions F5, 79, C6 xx, 4F, F1.

The machine does not know that any of this has happened. The machine just executes machine instructions. It doesn't care whether you those instructions come from an assembler translating a built-in code like "MVI", or a macro defined by you - or from a compiler. It doesn't matter. It is all the same. Machine instructions are machine instructions.

Thus to answer, literally, the question you asked: as far as the machine is concerned, executing the program, "assembly macros" do not exist, and do not need to be loaded. But I hope the longer answer has given you a clearer understanding.

$\endgroup$
3
  • $\begingroup$ I don't think so. I understand machine instructions (what I call machine instructions) are actual mechanical, like choosing input in a multiplexer. And then, you can combine multiple (arbitrarily) with software. In the CPU architecture in nandgame.com and NAND to Tetris Coursera course (the same one, nandgame is based on NAND to Tetris course material), some of the very standard instructions are added with software. This is on one level in nandgame. The stack operations for example. What I was wondering is at what level such things boot in a hierarchy of software in a computer. $\endgroup$
    – BipedalJoe
    Sep 8, 2022 at 18:36
  • $\begingroup$ Basically I think I understand the hardware good enough now after studying for a year or a few years, but I have very poor understanding of how it boots up software on top of software after that. I assume some software levels are important to be able to do just about anything (kernel maybe, file system), but I could have wrong impression about that. $\endgroup$
    – BipedalJoe
    Sep 8, 2022 at 18:38
  • $\begingroup$ Or maybe I got it wrong. Compilers are what need the macros. The compiled code is just each individual instruction. mynor.org was adding macros at the hardware level, could be why I missed that. Or, MyNor adds the macros because the code would be absurdly long otherwise. And I was thinking maybe CPUs tend to add some macros at the hardware level too. In a ROM or something. To optimize how much memory is needed to store the actual programs. And I was thinking maybe something like that might also boot up early on. Basically, is it hardware, or in some kind of operative system? $\endgroup$
    – BipedalJoe
    Sep 8, 2022 at 18:41
2
$\begingroup$

You may be referring to the "macros" that can be defined when using a symbolic assembler for development. Such a program is a translator from a human readable representation of the processor opcodes to machine language (see illustration, middle columns and left columns).

In this frame, a macro is just a shorthand to replace a (short) sequence of instructions that are often used. The macros can be defined by the user (in the program itself) or be predefined by the assembler. They can also have arguments, to handle variable parts.

But in all cases, the assembler substitutes them by their definition before translation and they just don't appear in the generated machine code.

enter image description here

enter image description here

To answer your question direcly: macros appear nowhere in binary code (compiled or assembled programs).

$\endgroup$
1
  • $\begingroup$ In mynor.org, the instruction set is expanded at hardware level with ROM with "instruction macros". This reduces the memory needed for programs. It seems possible the same might be used in normal computers too. It seems like x86 instruction set includes some instructions that are combinations of instructions (or maybe i got that wrong, they appear sometimes but maybe that is not an instruction set level but higher. ) I don't think my assumption is very far fetched, I understand machine code but I also understand that having "instruction macros" reduces memory requirements. $\endgroup$
    – BipedalJoe
    Sep 8, 2022 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.