Lecture Introduction to computing systems: Chapter 7 - Yale N. Patt, Sanjay J. Patel

Chapter 7 - LC-2 assembly language. The main contents of this chapter include all of the following: Assembly language programming - Moving up a level, an assembly language program, the assembly process, beyond the assembly of a single assembly language program. | Chapter 7 LC-2 Assembly Language It’s hard to write code in 1’s & 0’s! Assembly language makes it possible to write Machine Language code each line of assembly language is translated into a single ML instruction A program called the Assembler does the translation and provides useful tools: use of labels - symbolic names for address locations automatic conversion of binary / hex / decimal pseudo-ops 7 - A sample program 01 ; 02 ; Program to multiply an integer by the number 6 03 ; 04 .ORIG x3050 05 LD R1, SIX 06 LD R2, NUMBER 07 AND R3, R3, #0 ; clear R3 to hold the product 08 ; 09 ; The inner loop 0A ; 0B AGAIN ADD R3, R3, R2 0C ADD R1, R1, #-1 ; keep track of iterations 0D BRp AGAIN 0E ; 0F HALT 10 ; 11 NUMBER .BLKW 1 12 SIX .FILL x0006 13 ; 14 .END 7 - Assembly Language Instructions Formats LABEL OPCODE OPERANDS ; COMMENTS LABEL PSEUDO-OPS ; COMMENTS Opcode Symbolic name for the 4-bit ML opcode Label Symbolic name for a memory location. It is used to: indicate the target of a branch instruction, . AGAIN in location 0B indicate the location of a stored value or array, . NUMBER and SIX Comments intended for humans only: explanation of code, visual display 7 - Pseudo-Ops are directives to the assembler they are not translated into ML instructions LC-3 Pseudo-Ops: .ORIG address Tells assembler where to locate the program in memory (starting address). .FILL value Store value in the next location in memory. .BLKW n Set aside a block of n words in memory. .STRINGZ string Store the string, one character per word, in memory. Add a word of x0000 after the string. .END Marks the end of the source program (not to be confused with the instruction HALT!) .EXTERNAL The label so indicated is allocated in another module. 7 - A partial assembly sample .ORIG x3000 AND R1, R1, #0 ADD R1, R1, #10 LD R2, Twenty LD R3, Ess HALT Twenty FILL x0014 .BLKW 2 Ess .FILL “S” .STRINGZ “Hi” .BLKW 3 .END x3000: AND R1, R1, b0 0000 x3001: ADD R1, R1, b0 1010 x3002: LD R2, | Chapter 7 LC-2 Assembly Language It’s hard to write code in 1’s & 0’s! Assembly language makes it possible to write Machine Language code each line of assembly language is translated into a single ML instruction A program called the Assembler does the translation and provides useful tools: use of labels - symbolic names for address locations automatic conversion of binary / hex / decimal pseudo-ops 7 - A sample program 01 ; 02 ; Program to multiply an integer by the number 6 03 ; 04 .ORIG x3050 05 LD R1, SIX 06 LD R2, NUMBER 07 AND R3, R3, #0 ; clear R3 to hold the product 08 ; 09 ; The inner loop 0A ; 0B AGAIN ADD R3, R3, R2 0C ADD R1, R1, #-1 ; keep track of iterations 0D BRp AGAIN 0E ; 0F HALT 10 ; 11 NUMBER .BLKW 1 12 SIX .FILL x0006 13 ; 14 .END 7 - Assembly Language Instructions Formats LABEL OPCODE OPERANDS ; COMMENTS LABEL PSEUDO-OPS ; COMMENTS Opcode Symbolic name for the 4-bit ML opcode Label Symbolic name for a memory location. It is used to: indicate the target of

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.