1 / 13

CS33: Introduction to Computer Organization Week 1 – Discussion Section

This discussion section covers topics such as data endianess, x86 assembly basics, registers, memory addressing, and various x86 assembly instructions.

jeffreym
Download Presentation

CS33: Introduction to Computer Organization Week 1 – Discussion Section

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS33: Introduction to Computer OrganizationWeek 1 – Discussion Section Atefeh Sohrabizadeh atefehsz@cs.ucla.edu 10/4/19

  2. Discussion Class Materials • You can find all the files we use in discussion class from: • http://vast.cs.ucla.edu/~atefehSZ/teaching/cs33.html

  3. Agenda • Lab1: DataLab Sample Example • Big Endian vs. Little Endian • x86 Assembly: Basics

  4. Datalab Example 1

  5. Datalab Example 2

  6. Endian • Big endian • Least significant byte has the highest address • E.g. : x = 0x1234567a, &x = 0x100 • Little endian • Least significant byte has the lowest address

  7. Registers • Memory units that we can access them at relatively the speed of execution of instructions • A program brings the data it needs to registers and work on them • Each register can store a number of bits • The registers on a 64-bit addressable machine are 64-bits registers

  8. x86-64 Registers • Has 16 general-purpose registers • Example • %rax: full 64-bits stored in the register rax • %eax: lower 32-bits stored in the register rax • %ax: lower 16-bits stored in the register rax • %al: lower 8-bits stored in the register rax • %ah: upper 8-bits of lower 16-bits stored in the register rax

  9. x86 Assembly • General format • [operation] [source] [destination] • The suffix of an operation determines how much data to work on • b: work on a byte • w: work on a word (16 bits) • A word on a 64-bit machine is 64 bits, but when x86 was developing a word was 16 bits • l: work on a long/double word (32 bits) • q: work on a quad word (64 bits)

  10. mov_ family • movb: move a byte • movw: move a word (16 bits) • movl: move a long word (32 bits) • movq: move a quad word (64 bits) • Examples: • movq %rax, %rbx# %rbx = the value stored in rax (%rax) • movq %rax, (%rbx) # value of memory address stored in rbx = %rax • () means: treat bit vector in the register as memory address • movl $0x1abc, %rax# %rax = 0x1abc • $ indicates a constant number value (immediate) • movl 4(%rbx), %rax# %rax = value of (memory address stored in rbx + 4(bytes))

  11. Memory Addressing • General form: • D(Rb, Ri, S) : Mem[Reg[Rb] + S*Reg[Ri] + D] • Example: • (Rb): Mem[Reg[Rb]] • (Rb, Ri): Mem[Reg[Rb] + Reg[Ri]] • D(Rb, Ri): Mem[Reg[Rb] + Reg[Ri] + D] • (Rb, Ri, S): Mem[Reg[Rb] + S*Reg[Ri] ] Scale Base register Displacement Index register

  12. lea_ instruction • “Load Effective Address” • A faster way to calculate the address • Or just do arithmetic • leaq (%rax), %rbx# %rbx = the value in rax • Not the memory address stored in rax • Comparison to movq • movq 2(%rax, %rbx, 8), %rcx# %rcx = Mem[%rax + 8*%rbx + 2] • leaq 2(%rax, %rbx, 8), %rcx# %rcx = %rax + 8*%rbx + 2

  13. Other Instructions • addqsrc, dst# dst = dst + src • subqsrc, dst# dst = dst – src • salqsrc, dst# dst = dst << src • sarqsrc, dst# dst = dst >> src • negqsrc, dst# dst = -dst • Check section 3.5 of the book for more instructions

More Related