











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
Some concept of Machine Organization are Anatomy, Cache Access Time, Instruction Formats, Instruction Formats, Instruction Formats, Multidimensional Meshes, Network Processors, Snooping Protocol. Main points of this lecture are: Assembly Language, Assembly Process, Using the Editor, Simulator, Assembly Language Programming, Instruction, Assember Directive, Comment, Whitespace, Instruction
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Compute the Sum of 12 Integers
R1 ← x R3 ← 0 (Sum) R2 ← 12(count)
NO
YES
R1: “Array” index pointer (Begin with location 3100) R3: Accumulator for the sum of integers R2: Loop counter (Count down from 12) R4: Temporary register to store next integer Docsity.com
Address Instruction Comments
x3004 (^0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1) If Z, goto x300A
x3005 (^0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0) Load next value to R
x3006 (^0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0) Add to R
x3007 (^0 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1) Increment R1 (pointer)
X3008 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 Decrement R (counter) x3009 (^0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0) Goto x
R1: “Array” index pointer (Begin with location 3100) R3: Accumulator for the sum of integers
R2: Loop counter (Count down from 12) R4: Temporary register to store next integer Docsity.com
Compute the Sum of 12 Integers
; Program to multiply a number by the constant 6 ; .ORIG x
LD R1, SIX ; Constant 6 LD R2, NUMBER ; Number AND R3, R3, #0 ; Clear R ; The product. ; The multiply loop
AGAIN ADD R3, R3, R2 ; Accumulate product ADD R1, R1, #-1 ; Dec counter BRp AGAIN
HALT
NUMBER .BLKW 3 ; Value of Number SIX .FILL x
.END
Symbol Table: Symbol Address AGAIN x NUMBER x SIX x305A
clear R
add R3 to R
decrement R
R1 = 0?
HALT
No
Yes
Code Equivalent Description
.ORIG x3000 ; begin at x ; input two numbers IN ;input an integer character (ascii) {TRAP 23} LD R3, HEXN30 ;subtract x30 to get integer ADD R0, R0, R ADD R1, R0, #0 ;move the first integer to register 1 IN ;input another integer {TRAP 23} ADD R0, R0, R3 ;convert it to an integer ; add the numbers ADD R2, R0, R1 ;add the two integers ; print the results LEA R0, MESG ;load the address of the message string PUTS ;"PUTS" outputs a string {TRAP 22} ADD R0, R2, #0 ;move the sum to R0, to be output LD R3, HEX30 ;add 30 to integer to get integer character ADD R0, R0, R OUT ;display the sum {TRAP 21} ; stop HALT ;{TRAP 25}
; data MESG .STRINGZ "The sum of those two numbers is: “ HEXN30 .FILL xFFD0 ; -30 HEX HEX30 .FILL x0030 ; 30 HEX .END
; Add R3=R0+R1, R2=0 indicates no overflow ; .ORIG x
AND R2, R2, #0 ;Initially R2=0 (no Overflow assumed) ADD R3, R0, R1 ;R3=R0+R
; test for overflow ADD R0, R0, #0 ;test R BRN NEG ;Branch if RO negative ADD R1, R1, #0 ;R0 pos, test R BRN DONE ;R0 pos, R1 neg -> No overflow
ADD R3, R3, #0 ;R0 pos, R1 pos, maybe, test R BRZP DONE ;R3 also pos -> no overflow ADD R2, R2, #1 ;Set R2=1 indicating overflow BRNZP DONE
R0NEG ADD R1, R1, #0 ;R0 neg, test R BRZP DONE ;R0 neg, R1 pos -> No overflow
ADD R3, R3, #0 ;R0 neg, R1 neg, maybe, test R BRN DONE ;R3 also neg -> no overflow ADD R2, R2, #1 ;Set R2=1 indicating overflow
DONE HALT .END
; Program to count occurrences of a character in a file. ; Character to be input from the keyboard. ; Result to be displayed on the monitor. ; Program only works if no more than 9 occurrences are found. ; ; ; Initialization ; .ORIG x AND R2, R2, #0 ; R2 is counter, initially 0 LD R3, PTR ; R3 is pointer to character file GETC ; R0 gets input character LDR R1, R3, #0 ; R1 gets first character from file ; ; Test character for end of file ; TEST ADD R4, R1, #-4 ; Test for EOT (ASCII x04) BRz OUTPUT ; If done, prepare the output ; ; Test character for match. If a match, increment count. ; NOT R1, R ADD R1, R1, R0 ; If match, R1 = xFFFF NOT R1, R1 ; If match, R1 = x BRnp GETCHAR ; If no match, do not increment ADD R2, R2, # ; ; Get next character from file. ; GETCHAR ADD R3, R3, #1 ; Point to next character. LDR R1, R3, #0 ; R1 gets next char to test BRnzp TEST ; ; Output the count. ; OUTPUT LD R0, ASCII ; Load the ASCII template ADD R0, R0, R2 ; Covert binary count to ASCII OUT ; ASCII code in R0 is displayed. HALT ; Halt machine ; ; Storage for pointer and ASCII template ; ASCII .FILL x0030 ; ASCII offset PTR .FILL x4000 ; PTR to character file .END