Lecture 4 assembly language


Published on

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lecture 4 assembly language

  1. 1. ASSEMBLY LANGUAGET S Pradeep KumarVIT University – Chennai Campushttp://www.pradeepkumar.org
  2. 2. Topics• CPU Behavior• Accumulator Based CPU• Assembly language• Pros and Cons of Assembly Language• Elements of Assembly Language• Example: AC = AC x N• Greatest Common Divisor• Macros and Subroutines
  3. 3. CPU Behavior
  4. 4. Accumulator based CPU• All the arithmetic calculations happens at the Accumulator register• Instructions are fetched by the program control Unit (PCU).• They are executed in Data processing Unit (DPU)• Instruction are typically look like this• X1 = fi (X1, X2)• X1, X2 denotes a CPU register (AC, DR, or PC) or an external memory location M (address)
  5. 5. Accumulator based CPU• fi is operation performed by the ALU are limited to Fixed point addition, subtraction, shifting and logical operations.
  6. 6. Assembly Language• An assembly language is a symbolic representation of the machine language of a specific processor, augmented by additional types of statements that facilitate program writing and that provide instructions to the assembler• An assembler is a program that translates assembly language into machine code.• Assembly Language is hardware dependent with a different assembly language for each type of processor.
  7. 7. Advantages of Assembly Language overHLL• Debugging and Verification• Making compilers• Embedded systems• Hardware drivers and system code• Accessing instructions that are not accessible from HLL• Self modifying code• Optimizing code for size and speed• Function libraries
  8. 8. Disadvantages of Assembly language• Development time• Reliability and security• Debugging and verifying is difficult• Maintainability• Portability• Compilers have been improved a lot in recent years
  9. 9. Assembly language elements• Label• Mnemonic• Operands• Comment
  10. 10. Example: AC = AC x NLabel Mnemonic, operands CommentsOne 00…001 The constant oneMulti N The multiplierAc 00...000 Location for initial value of Y in ACProd 00…000 Location for partial product P ST ac Save initial value of Y of ACLoop LD mult Load N into AC to test for termination BZ exit Exit if N=0; otherwise continue LD one Load 1 into AC MOV DR, AC Move 1 from AC to DR LD mult Load N into AC to decrement it SUB Subtract 1 from N ST mult Store decremented N LD ac Load initial value Y of AC MOV DR, AC Move Y from AC to DR
  11. 11. Continued…Label Mnemonic, operands comments LD prod Load current partial product P ADD Add Y to P ST prod Store the new partial product P BR loop Branch to LoopExit …..
  12. 12. Example - GCD
  13. 13. Example - GCD
  14. 14. Macros and Subroutines• Macros and subroutines are useful for the simplification of program• Group of instructions to be treated as a single entities• Name MACRO Operand,… ………} ENDM• Macros are helpful in creating new opcode names• Introduce new data types and addressing modes
  15. 15. Macros• Example of MACRO• LDAI MACRO ADR LDHL ADR MOV A,M ENDMLater,LDAI 1000Hbecomes a separate instruction
  16. 16. Subroutines• Also called as procedure• A subroutine definition is assembled into object code• Two executable instructions • CALL or JUMP TO SUBROUTINE • RETURN CALL SUB1NEXT ….. …...SUB1 …… …… RETURN
  17. 17. Subroutines
  18. 18. EVALUATION……