Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture Lecture 3 C and Assembly. Intro to Assembly Language MIPS and Intel Variables and Constants int count = 10, I, j, k; count.word.

Similar presentations


Presentation on theme: "Computer Architecture Lecture 3 C and Assembly. Intro to Assembly Language MIPS and Intel Variables and Constants int count = 10, I, j, k; count.word."— Presentation transcript:

1 Computer Architecture Lecture 3 C and Assembly

2 Intro to Assembly Language MIPS and Intel Variables and Constants int count = 10, I, j, k; count.word 10 i.word j.word Count DD10 iDD? jDD?

3 Byte size variables char sum = 1, total= 5; char uni[10] =“university”; sum.byte 1 total.byte 5 uni.byte “u”,”n”, “i” etc; sum db 1 total db 5 uni db “u”,”n”, “i” etc;

4 Strings string str (“hello world”); str.asciiz “hello world” str db “hello world”

5 Arrays int age[100]; age.word 0:100 ; 100 words initialized to zero age dw 100 dup(0); 100 words initialized to zero

6 Assignment count = count +1;.data#Data Part count.word 10 //MIPS Assembly.text# Code part main: la R1, count # (load address works in spim) #R1 has address of count lw R2, 0(R1)# R2 has the value of count addi R2, R2, 1# Increment sw R2, 0(R1)# Save count, if need be

7 Another Example i = age[20] +age[0] + count;.data age.word 0:100 ; 100 words initialized to zero.text main: la R3, age#R3 has base address of age; lw R4, 80[R3]#20 * 4 = 80, R4 = age[20] lw R5, 0(R3)#R5 = age[0] add R4, R4, R5# add R4, R4, R2#R2 had value of count above

8 Control (WHILE) count = 0; while (count < 21) { age[count] = age[count+1]; count = count+1;;count need not assigned a memory location } laR6, age ; R6 = address of age[0] addiR2, R0, 0; R2 = count = 0 lable1: mul R4, R2, 4 ; R4 has address of count th element add R5, R6, R4:R4= count *4 lw R7, 4(R5);R7 = age[count+1] sw R7, 0(R5); age[count] = R7 addi R2, R2, 1; Count = count +1; slti R8, R2, 21; R8 = 1 if count<21 bnez R8, label1

9 For Statement Total = 0; For (i= 0; i<100; i ++) {total = age[i] + total;} la R1, age #R1 has address of count la R22, Total lw R2, 0(R1)# R2 has the value of count addi R5, R0, 0# i = 0 ; R5 is i addi R15, R0, 0# R15 is running sum addi R10, R0, 100# R10 = 100 Xy:sltR11,R5,R10# check R5 is R5 < R10 (R10 is count) beR11, R0, lable# loop until mul R6, R5, 4 # R6 has address of i th element of age add R6, R6, R1# R4 = address of age lwR20, 0(R6)#R20 = age[i] addR15, R15, R20# total = total + age[i] swR15, 0(R22)# R22 is address of total addiR5,R5,1# i = i+1; bXy:# Unconditional branch lable:

10 IF … then if (count == max) { I = 5;} else { I = 20;} Instructions after if #assume R4 has the value of count, R7 has value of MAX and I is R5 bne R4, R7, else addiR5, R0, 5 bexit else:addiR5, R0, 20 exit: Instructions after if

11 Classifying Instruction Set Architectures Stack Register- Register Register – Memory Accumulator Memory – Memory


Download ppt "Computer Architecture Lecture 3 C and Assembly. Intro to Assembly Language MIPS and Intel Variables and Constants int count = 10, I, j, k; count.word."

Similar presentations


Ads by Google