4-Bit Computer Simulator - Generation 2
Jan 22, 2020
So I think we're ready for our next level of abstraction. The use of an assembly language. This is a higher level language. It's not a high level language. Higher level than machine language, and as you can see from this table, basically every machine code is mapped to a symbolic opcode. So zero zero zero one is now LDA for load the accumulator. Zero zero one zero is now STA store accumulated, and so on. These are much easier to remember than the binary opcodes. Similarly, when we want to declare variables, we can now use a variable declaration statement, and we can name the variables with symbolic names like a, and so forth, and give them an initial value. And again, we can move up to decimal notation rather than having to deal in binary. So let me demonstrate how we would do a program. It works pretty much the same way as with the machine language editor. So I'm going to set a to 20. The data has to be declared and initialized at the beginning. B to 20, C to 22, D is going to be my divisor. I'm going to divide these three numbers and take the average, and var R is going to be my result. And I'm just going to give that a value is zero. Another big advantage of the assembly language is we don't need to figure out ourselves what memory locations to put these into. They're going to go into the same ones that we would have put him into, but the assembler would take care of all that for us. So I need to load a into the accumulator. I need to add B to it. I need to add C to it. I need to divide the accumulator by D, store that result in R and then print R, and then go up. So that's my assembly language program. When I assemble it, what will happen is the assembler, the software that translates the assembly language, will translate it into machine language, and put it in this window. This is what we used to have to type before. And now it's done automatically for us. Now we can load it into the machine. We can do the fetch execute steps if we want to step through it, but we can just run it. So 20 plus 20 plus 22 is 62 divided by three, we should get 20.66, but we're getting 20. And again, the reason for that is we are only doing integer division so any decimal part of the result will be thrown away. So I hope you see that raising the level of abstraction to an assembly language is a big gain for the programmer making it much easier to write programs and allowing us to bracket or put aside some of the underlying details of the machine architecture, including its binary nature.