35
mith College Computer Science Dominique Thiébaut [email protected] CSC231-Assembly Week #2 Fall 2018

CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

mith College

Computer Science

Dominique Thiébaut [email protected]

CSC231-AssemblyWeek #2 Fall 2018

Page 2: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Outline• Review + Lab 1: uP simulator Lab

• Lab2: Emacs (do on your own)

• Lab3: Assembly

• Assembly + Linking Process

• Object files

• DB directive: Everything is a byte!

• HexDump: we need to learn hexadecimal!

• Ascii Table

Page 3: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Review

Page 4: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Review

Processor +

ACPC

3

Add 1

HaltStore [9]

Load [9]

11 10 9 8 7 6 5 4 3 2 1 0

Page 5: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Similarity w/ Hand Calculator

Page 6: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Computer Simulator Review

http://www.science.smith.edu/dftwiki/media/simulator/

http://bit.ly/2jTJswI

Page 8: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Outline• Review + Lab 1: uP simulator Lab

• Lab2: Emacs (do on your own)

• Lab3: Assembly

• Assembly + Linking Process

• Object files

• DB directive: Everything is a byte!

• HexDump: we need to learn hexadecimal!

• Ascii Table

Page 9: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Emacs

Page 10: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Demo: Emacs (Do lab on your own)

• ssh to aurora ssh -Y [email protected]

• Emacs demo

• Basic commands

emacs -nw helloWorld.asm

^X^C^G^D^K^Y

cursor keys

Page 11: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Shell

Page 12: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Shell

Page 13: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

3 Useful Linux Commands

• ls (ell ess) list all files in a folder/directory

• cp copy file

• cd change directory

Page 14: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Linux Commandscommand -switches file-name(s)

Page 15: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Linux Commands

ls -1 ls *.asm ls *.o ls hello* ls -l

man ls

command -switches file-name(s)

Page 16: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

We stopped here last time…

Page 17: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

GoogleYouTubePython

Page 18: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Solution ProgramsFor Simulator Lab

; Solution for Problem 1 LOAD 22  ; load 22 into the accumulator STORE [10]  ; STORE [11]  ; STORE [12]  ; HALT  ;

; Solution for Problem 2 LOAD 9  ; load 22 into the accumulator STORE [20]  ; LOAD 19  ; STORE [21]  ; LOAD 13  ; STORE [22]  ; HALT  ;

; Solution for Problem 30000: LOAD [10]  ;0002: STORE [11]  ;0004: STORE [12]  ;0006: STORE [13]  ;0008: HALT  ;0010: 55  ;

Typical

Midterm

Question!

Page 19: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Solution ProgramsFor Simulator Lab

; Problem 4; Part 1LOAD [8]  ;ADD 2   ;STORE [8] ;HALT  ;8: 55 ;

; Part 20000: LOAD [20]  ;0002: ADD 2 ;0004: STORE [20] ;0006: LOAD [21] ;0008: ADD 2 ;0010: STORE [21] ;0012: HALT ;0020: 55 ;0021: 13 ;

; Solution for Problem 50000: LOAD [10]  ;0002: ADD 5   ;0004: STORE [10] ;0006: JUMP 0  ;0010: 55   ;

; Solution for Challenge

0000: LOAD [10]  ;0002: ADD [10]   ;0004: ADD [11]   ;0006: STORE [12] ;0008: HALT  ;0009: HALT  ;0010: 3   ;0011: 5  ;0012: 0   ;

Page 20: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Outline• Review + Lab 1: uP simulator Lab

• Lab2: Emacs (do on your own)

• Lab3: Assembly

• Assembly + Linking Process

• Object files

• DB directive: Everything is a byte!

• HexDump: we need to learn hexadecimal!

• Ascii Table

Page 21: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

LAB TIME!

• Demo

• Do the lab in pair

• Printing strings and understanding db

http://www.science.smith.edu/dftwiki/index.php/CSC231_Hello_World_Lab_2018

Page 22: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Skeleton

Page 23: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Hello World!

Page 24: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Assembly+Linking

xxx.asm xxx.o xxx

nasm ld

Page 25: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Assembly+Linking

xxx.asm yyy.asm

xxx.o yyy.o

xxx

nasm ld

Page 26: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

DB: byte storage

Page 27: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Data Section vs Memorymessage db "hello",10

Page 28: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Data Section vs Memorymessage db "hello" db 10

Page 29: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Data Section vs Memory

message db "h","e","l","l","o" db 10

Page 30: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Data Section vs Memory

message db "hel" db "lo" db 10

Page 31: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Data Section vs Memorymessage db 104,"el" db "lo" db 10

Page 32: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Exercise section .data

msg1 db "lo " db "hel"

msg3 db "world!", 10msgLen equ$-msg3

_start:mov eax, 4 mov ebx, 1 mov ecx, msg1+3 mov edx, 3int 0x80

mov eax, 4 mov ebx, 1 mov ecx, msg1 mov edx, 3 int 0x80

mov eax, 4 mov ebx, 1 mov ecx, msg3mov edx, msgLen ; # of charsint 0x80

Page 33: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

We stopped here last time…

Page 34: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Element of Style

Don't!

Page 35: CSC231-Assembly · D. Thiebaut, Computer Science, Smith College Outline • Review + Lab 1: uP simulator Lab • Lab2: Emacs (do on your own) • Lab3: Assembly • Assembly + Linking

D. Thiebaut, Computer Science, Smith College

Element of Style

Better!