





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to machine language and assembly language programming through the example of a simple machine. It covers the use of registers, data transfer and processing instructions, and the assembly process. Students of computer science or engineering may find this useful for gaining a deeper understanding of low-level programming and computer architecture.
Typology: Slides
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































Assembly Language Programming
We will try to understand theuse of Machine Language bydesigning a simple machinewith the given parameters asdefined in the next pages
■ data transfer, ■ data processing, and ■ program control.
■ load, ■ store, and ■ move data between the registers AC(Accumulator) and DR (Data Register).
■ add, subtract, and, and not.
■ jump and conditional jump.
■ 4 bits for the operation code and 12 bits forthe address.
Jump to instruction on adr if AC = adr 1010 Jump to instruction with address adr adr 1001 Complement contents of AC 1000 AND bitwise DR to AC 0111 Subtract DR from AC 0110 Add DR to AC 0101 Copy the contents DR to AC 0100 Copy the contents AC to DR 0011 Store contents of AC into memory (location adr). adr 0010 Load operand from memory (location adr) into AC adr 0001 Stop execution 0000 Meaning of Instruction Operand Op Code
Data Value is 0 0000 0000 0000 0000 0000 0001 0000 Data Value is 96 0000 0000 0110 0000 0000 0000 1110 Data Value is 350 0000 0001 0101 1110 0000 0000 1100 Stop 0000 0000 0000 0000 0000 0000 1010 Store contents of AC in location 16 0010 0000 0001 0000 0000 0000 1000 Add DR to AC 0101 0000 0000 0000 0000 0000 0110 Load the contents of location 14 intoAC 0001 0000 0000 1110 0000 0000 0100 Move contents of AC to DR 0011 0000 0000 0000 0000 0000 0010 Load the contents of location 12 inAC 0001 0000 0000 1100 0000 0000 0000 Description Binary Instruction Memory Location
Assembly programs are written with shortabbreviations called mnemonics. A mnemonic is an abbreviation thatrepresents the actual machine instruction. Assembly language programming is thewriting of machine instructions in mnemonicform, where each machine instruction isreplaced by a mnemonic. Clearly the use of mnemonics would makeprogramming at this low level easier and moremanageable.
Instruction Mnemonics and Syntax An assembly program consists of a sequenceof assembly statements. Each line of an assembly program is split intothe following four fields: ■ label, ■ operation code (opcode), ■ operand, and ■ comments. Comment(Optional) Operand (Required in some instructions Operation Code (Required) Label (optional)
Instruction Mnemonics and Syntax
AND bitwise DR to AC AND Complement the contents of AC NOT Jump to instruction adr if AC = 0 adr BZ Jump to instruction with address adr adr BRA Subtract DR from AC SUB Add DR to AC ADD Copy the contents of DR to AC MOV Copy the contents of AC to DR. MOVAC Save contents of AC in memory (location x). x ST Load operand from memory (location x) into AC. x LD Stop Execution STOP Meaning of Instruction Operand Mnemonics
Assembler directives are commands that areunderstood by the assembler and do notcorrespond to actual machine instructions. Assembler directives are commands that areunderstood by the assembler and do notcorrespond to actual machine instructions. In assembly language programs symbols areused to represent numbers in order to makethe code easier to read, understand, anddebug.
Assembly and Execution of Programs A program written in assembly language needs to betranslated into binary machine language before it canbe executed. Three steps exist in the assembly and executionprocess. ■ The assembler reads the source program in assemblylanguage and generates the object program in binary form.The object program is passed to the linker. ■ The linker will check the object file for calls to procedures inthe link library. The linker will combine the requiredprocedures from the link library with the object program andproduce the executable program. ■ The loader loads the executable program into memory andbranches the CPU to the starting address. The programbegins execution.
Assemblers ■ A simple assembler scans the entire assemblyprogram twice, where each scan is called a pass. ■ During the first pass, it generates a table thatincludes all symbols and their binary values. Thistable is called the symbol table. ■ During the second pass, the assembler will usethe symbol table and other tables to generate theobject program, and output some information thatwill be needed by the linker
Data Structures ■ The assembler uses at least three tables toperform its functions: