Presentation is loading. Please wait.

Presentation is loading. Please wait.

Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems.

Similar presentations


Presentation on theme: "Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems."— Presentation transcript:

1 Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems http://www.utdallas.edu/~pervin P4 Thursday: Finish Chapter P4 Tuesday 2-14-12

2 Overview (P4) Arrays and Pointers

3 Decoders & Multiplexers – Dodge Lecture 6 http://www.utdallas.edu/~dodge/EE2310/lec6.pdf http://www.utdallas.edu/~dodge/EE2310/lec6.pdf Go over this carefully!! For Lab Assignment #1, see the next slide.

4 Design Problem You have now seen how to go from a requirement to a truth table to a Boolean Expression to a circuit (and even how to simplify the circuit). You now get to do a design. Do a first try by yourself. Then you may review and complete your design with your EE 2110 lab partner. Here is the requirement (“spec”): A circuit has three input variables, x, y, and z. Its output is 1 for the conditions x, y, z = 0, x, y = 0; z = 1, and x = 0; y, z = 1. Do the following: – Make a truth table from the requirements. – Devise an SOP Boolean expression from the truth table. Simplify it using the relationships discussed today, but keep in SOP form. (Do not use a Karnaugh map!) – In EE 2110 Lab. 1, build your design (see Lab. 1 instructions). – Using all combinations of the input variables, demonstrate with your partner to the lab TA that your real circuit obeys your truth table. Lecture #4: Boolean Algebra and Combinational Digital Logic © N. B. Dodge 01/12

5 Arrays and Pointers array:.space 100 #100 bytes (25 words) in.data section int[] array; For example, suppose we have the following code:.data array:.space 100.text … # some code la $t0,array The SPIM assembler will give us a line of code such as 0x3c081001 lui $8, 4097 [array] ; 7: la $t0,array The “[array]” note is just to help the programmer and is not part of the code. The instruction itself (lui $8,4097) places 0x1001 = 4097 DEC in the upper half (lui = Load Upper Immediate) of register 8 ($t0). The agreement is that our portion of the.data segment is to start at location 0x10010000 and that is what is put in $t0.

6 Now suppose we started our.data segment differently:.data begin:.asciiz “Begin: ” # 8 characters (space + zero byte) array:.space 100 end:.asciiz “End”.text … # some code la $t0,array The assembler will give us two lines of code such as 0x3c011001 lui $1, 4097 [array] ; 8: la $t0,array 0x34280008 ori $8, $1, 8 [array] Note: 0x3c011001 lui $1, 4097 [end] ; 10: la $t1,end 0x3429006c ori $9, $1, 108 [end]

7 .word directive.data begin:.asciiz “Begin:” #NOTE: no space worda:.word 0xffffffff array:.space 100 wordb:.word 0xeeeeeeee end:.asciiz “End”.text … # some code la $t0,array Now we get [0x10010000] 0x69676542 0x00003a6e 0xffffffff 0x00000000 [0x10010010]...[0x1001006c] 0x00000000 [0x1001006c] 0x00000000 [0x10010070] 0xeeeeeeee 0x00646e45 0x00000000 0x00000000 [0x10010080]...[0x10040000] 0x00000000

8 For loop for( i == 0 ; i < 25 ; i++) {array[i] = i;} The assembler code for this statement could be: # assume: $t0 contains the address of the 100 bytes # (maybe after an la $t0,array instruction) # assume: $t1 contains the integer 25 # (the number of words desired) # assume: $s0 contains the counter i; first initialize it to zero li $s0,0 # or move $s0,$0 or some other initialization loop: beq $s0,$t1,done # when i == 25 we are finished, branch sw $s0,0($t0) # array[i] = i; add $t0,$t0,4 # each integer is 4 bytes long add $s0,$s0,1 # increment the count by 1 j loop # go back and do the loop test again done: # ready for the next instruction; however, # $t0 no longer contains the address of the 100 bytes = 25 words!

9 reverse.s # reverse.s # Input: Any string # Output: The reverse of that string ######################################.data prompt:.asciiz "Input any string: " echo:.asciiz "\nThe reverse of \n\t" is:.asciiz "is \n\t" buffer:.space 78.word 0 #Null for reversed string #.text # Input string with prompt and echo main: li $v0,4 #string print function la $a0,prompt #prompt string syscall li $v0,8 #string read function la $a0,buffer #where to put it li $a1,78 #how many characters max syscall li $v0,4 #string print function la $a0,echo #echo string syscall li $v0,4 #string print function la $a0,buffer #buffer (including LF) syscall li $v0,4 #string print function la $a0,is #”is” syscall #start actual processing la $s1,buffer #get address of start of buffer addi $s1,77 #point to end of buffer #find end of actual string look: lb $t1,0($s1) #loading a byte bnez $t1,found #finally not Null sub $s1,1 #back up 1 byte j look #keep looking #reverse the string in place found: sub $s1,1 #ignore LF (0x0a) la $s2,buffer #point to beginning of string #here is the loop for reversing (s1 -> end; s2 -> beginning) rev: bgt $s2,$s1,done #middle found lb $t1,0($s1) #\ lb $t2,0($s2) # interchange sb $t1,0($s2) # the bytes sb $t2,0($s1) #/ add $s2,1 #update the pointer sub $s1,1 #update the pointer j rev #do it again #now print result done: li $v0,4 #string print function la $a0,buffer #reversed string with LF and Null syscall li $v0,10 #standard exit syscall #return to OS

10 BinarySearch.s int binary_search(int[] array, int size, int key) { int low = 0, high = size - 1; while( low <= high) { int mid = (low + high) /2; if( array[ mid ] < key) low = mid + 1; else if( key < array[ mid ]) high = mid -1; else return mid; } return NOT_FOUND; }

11 BinarySearch.s # BinarySearch.s # # Demonstrates binary search on a fixed list of integers.data # Data declaration section array:.word 2,5,11,23,47,95,191,383,767,998 prompt:.asciiz"\nInsert integer key (0 <= key): " ymsg:.asciiz "\nKey was found at position " nmsg:.asciiz "\nKey not found! ".text main: # Start of code section la$s0,array# Put address of array in $s0 li$s1,10 # Put count of elements in $s1 sll$s1,$s1,2# 4n byte = bytecount input: li$v0,4 # Print_string function code la$a0,prompt # Prompt for key syscall li$v0,5# Get key syscall bltz$v0,exit # Look for sentinal (negative) move $s2,$v0# Put key in $s2 li$t0,0# $t0 = low = 0 sub$t1,$s1,4 # $t1 = high = bytecount-4 (bytes) loop: bgt$t0,$t1,fail # while( low <= high ) add$t2,$t0,$t1 # $t2 = mid = low + high sra$t2,$t2,3 # mid = (low + high) / 8 sll$t2,$t2,2 # mid = (low + high) / 2 (aligned) add$t3,$t2,$s0 # get lw $t3,0($t3) # array[mid] blt$t3,$s2,LH # if (array[mid] < key) blt$s2,$t3,RH # if (key < array[mid] jfound LH: add$t0,$t2,4# low = mid + 4 (bytes) jloop RH: sub$t1,$t2,4# high = mid - 4 (bytes) jloop # found found: li$v0,4# Print la$a0,ymsg# Label syscall sra$t2,$t2,2# bytes to indexes add$t2,$t2,1 # 1-based indexing move $a0,$t2# Print li $v0,1 # Answer syscall jinput# do it all again # not found fail: li$v0,4# Print la$a0,nmsg# Label syscall jinput # exit exit: li$v0,10 syscall

12


Download ppt "Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems."

Similar presentations


Ads by Google