DOC PREVIEW
UCLA COMSCI 33 - lectures 3 & 4

This preview shows page 1-2-17-18-19-35-36 out of 36 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS33 : Introduction to Computer OrganizationJochen Haber3400 Boelter [email protected]:Farnoosh Javadi ([email protected])Xingyu Ma ([email protected])Mo Xu ([email protected])Teng Xu ([email protected])Lecture: MW 4PM-6PMOffice Hours:M: 6PM-7PMW: 6PM-7PMBH4532BDiscussion:As Enrolled- 2 hours per weekSec 1A BH5419 F: 2PM-4PM Teng XuSec 1B BH5419 F: 4PM-6PM Xingyu MaSec 1C BH5273 F: 4PM-6PM Mo XuSec 1D BH9436 F: 4PM-6PM Farnoosh JavadiText:Randal E. Bryant and David R. O’Hallaron. “Computer Systems: A Programmer’s Perspective” 2nd Edition, Prentice Hall 2010.Inserted X86 programmers manual on CourseWeb.Back to memoryX86-64 Registers: (over IA32: added 32 bits, added general purpose, expanded FP registers)4 main registers4 index registers8 additional registersinstruction pointer6 segment pointers16 floating point registersstatus register- 22 -Main memoryHuge array of bytes (bits) Each byte has an address. Lets say that x is an int. x has address0x78,y is a char. Its address is 0x95. z is a short, its address is 0xb4.0 1 2 3 4 5 6 7 8 9 A B C D E F01234563 2 1 07 x x x x89 yA1 oB z zCDEF.Anything but char considered as an aggregate. Some machines store with least significant onright (big endian), some on the left (little endian). Can retrieve all at once depending on theinstruction.3 2 1 00x12345678 stored as [x ,x ,x ,x ] = [0x12,0x34,0x56,0x78] big endian3 2 1 0[x ,x ,x ,x ] = [0x78,0x56,0x34,0x12] little endianIA32: 2 -1 is maximum memory size32X86-64 2 -1 is maximum.64Flat vs Segmented memory model- 23 -Virtual memory: each user seems to have exclusive use of the entire memory. To one user, itlooks like:- 24 -Disk drive:Address on drive: cylinder (0-X), track (0-5), sector (0-Y)- 25 -storage capacity 7.25 Mtransfer rate 156 Kb/sechydraulically activated read heads- 26 -Track layout:- 27 -Caches:Cache is memory plus algorithmsSemi autonomous data gatherers: parallel process.Fetch from slower to faster: get more data, analyze patternsStore from faster to slower: maybe action request, keep copy: commit processCache speed in between. Depending on size.- 28 -How does it work from a software point of view?Program is just a string of operations in memory. Your program is a set of lines in a .txt (.c) file.freq.c:#include <math.h> /* sqrt */int frequency_of_primes (int n) { int i,j; int freq= n/2+1 ; for (i=9; i<=n; i= i+2) for (j=sqrt(i);j>1;--j) if (i%j==0) { --freq; break ; } return freq;}main.c:#include <stdio.h> /* printf */#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */int main (){ clock_t t; int f,i; i = 1000000 ; printf ("Calculating... %d ", i ); t = clock(); f = frequency_of_primes (i); printf ( "%d ",f); t = clock() - t; printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); return 0;}- 29 -Pre-process, compile, assemble link.Can stop/start process anywhere, combine any of these files using gcc or g++.- 30 -Assembly languageBook is IA32, lnxsrv at SEAS is X86-64.How to specify an operand% implies a register %rax, %eax, %ax, %al (64) (32) (16) (8)$ means “immediate” or exactly that value $0x5: the value 5parentheses means the value stored at (%rax)that address memory All typesType Form Operand value Name Immediate $num num Immediate Register %rax %rax Register Memory num (num) Absolute Memory ($rax) (%rax) Indirect Memory num(%rax) (num+%rax) Base+displacement Memory (%rax,%rbx) (%rax+%rbx) Indexed Memory num(%rax,%rbx) (num+%rax+%rbx) Indexed Memory (,%rax,s) (%rax*s) Scaled indexed Memory num(,%rax,s) (num+%rax*s) Scaled indexed Memory (%rax,%rbx,s) (%rax+%rbx*s) Scaled indexed Memory num(%rax,%rbx,s) (num+%rax+%rbx*s) Scaled indexed Note: s may only be 1, 2, 4 or 8- 31 -Examples:assume %rax has value 0x10, %rbx has value 0x40Specification Computation Address Value$0x5 <na> <na> 5%rax <na> <na> 0x100x5 0x05 0x05 0xfa(%rax) %rax 0x10 0xfe0x04(%rax) 0x04+%rax 0x14 0xfa(%rax,%rbx) %rax+%rbx 0x50 0xfa0x04(%rax,%rbx) 0x04+%rax+%rbx 0x54 0xf6(,%rax,4) %rax*4 0x40 0xfb0x05 (,%rax,2) 0x05+%rax*2 0x25 0xf8(%rax,%rbx,2) %rax+%rbx*2 0x90 0xf60x05 (%rax,%rbx,2) 0x05+%rax+%rbx*2 0x95 0xf10 1 2 3 4 5 6 7 8 9 A B C D E F0 ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f01 fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef2 fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee3 fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed4 fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec5 fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb6 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea7 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea e98 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea e9 e89 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea e9 e8 e7A f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea e9 e8 e7 e6B f4 f3 f2 f1 f0 ef ee ed ec eb ea e9 e8 e7 e6 efC f3 f2 f1 f0 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4D f2 f1 f0 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3E f1 f0 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3 e2F f0 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3 e2 e1- 32 -Assembly language instuctionsCombinations of source and destination implied. Proper operation code determined by compiler.Move instructions: source and destination immediate to register mov immediate,registerregister to register mov register,registermemory to register mov memory,registerimmediate to memory mov immediate,memoryregister to memory mov register,memoryObviously cannot move to an immediate: mov %rax,$0x40Moving from smaller to larger: sign extension or zero extensionmovs source,dest sign extensionmovz source,dest zero extensionMoving from larger to smaller, take only low order.- 33 -Stack manipulation instructions- 34 -Take a closer look at the stack portion:Actions during call%rip %rbp %rsp instruction action0x40048a 0xe450 0xe420 break at call0x400496 0xe450 0xe418 before push %rsp-8; %rip+5 stored at %rsp,%rip set toaddress of to_sub0x400497 0xe450 0xe4210 after push %rsp-8, contents of %rbp stored at %rsp0x40049a 0xe410 0xe410 after mov %rsp moved to %rbp0x40049e 0xe410 0xe3e0 after sub 0x30 subtracted from %rsp- 35 -Contents of memory around the stack. Be careful because this comes from GDB and it has some quirky ideas aboutendian. 0 4 8 C 0x7fffffffe3e0: 0x00000000 0x00000000 0xffffe44c 0x00007fff0x7fffffffe3f0: 0x00000000 0x00000000 0x004004f0 0x000000000x7fffffffe400: 0x00000000 0x00000000 0x78563412


View Full Document

UCLA COMSCI 33 - lectures 3 & 4

Download lectures 3 & 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lectures 3 & 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lectures 3 & 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?