Assembly Lesson

Transcription

Assembly Lesson
Assembly Lesson
Source le format
October 13, 2005
http://etud.epita.fr/ becoul a/asm/2005/
Copying this document
Copying this document
c 2004 ACU,
Copyright Alexandre Becoulet and Benoit Perrot
Permission is granted to copy, distribute and/or modify this document under the
terms of the GNU Free Documentation License, Version 1.2 or any later version
published by the Free Software Foundation; with the Invariant Sections being just
Copying this document, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is provided in the le COPYING.DOC.
Assembly Lesson - October 13, 2005
1
Table of Contents
Table of Contents
Assembly source le layout .................................................................... 3
Assembly le organization ...................................................................... 4
Assembly language statements ............................................................. 5
Example ....................................................................................................... 6
Assembly Lesson - October 13, 2005
2
Assembly source le layout
Assembly source le layout
1. Source le organization
2. Language statements
Assembly Lesson - October 13, 2005
3
Assembly le organization
Assembly le organization
Source le organized in dierent sections:
code
Contains program binary opcodes
data
Contains program global variables
rodata
Contains read-only program variables
Assembly Lesson - October 13, 2005
4
Assembly language statements
Assembly language statements
directives
Determine the assembler behavior
instructions
CPU instruction set, translated in binary format, written in output le
operands
Expressions containing register identiers, immediate operands, symbols
label
Between instructions, used to mark specic locations in source code
Assembly Lesson - October 13, 2005
5
Example
Example
.mod_load
.define
asm−s p a r c
FOO
.section code
5
.text
.mod_asm
o p c o d e s v8
add %g0 ,
FOO, % g1
.ends
Assembly Lesson - October 13, 2005
6
Example
Example
.mod_load asm−s p a r c
.mod_load out− e l f 3 2
.section code
.text
.mod_asm
mov
mov
o p c o d e s v8
0 x12 , % g1
0 x345 , % g2
add %g1 ,
% g2 , % g3
.ends
Assembly Lesson - October 13, 2005
7
Example
Example
.mod_load asm−s p a r c
.include s p a r c / v 8 . d e f
.section
.ends
d a t a .data
lbl :
.reserve 4
.section code . t e x t
.mod_asm o p c o d e s
.ends
v8
@ s e t .data : l b l , % g2
l d [%g2 ] , % g1
Assembly Lesson - October 13, 2005
8
Example
Example
.mod_load asm−s p a r c
.include s p a r c / v 8 . d e f
.section code . t e x t
.mod_asm o p c o d e s
v8
. e x p o r t main
. p r o c main
ret
.ends
.endp
Assembly Lesson - October 13, 2005
restore
9
Example
Example
.mod_load asm−s p a r c
.include s p a r c / v 8 . d e f
.section code . t e x t
.mod_asm o p c o d e s
v8
.extern exit
. p r o c my_exit
.ends
.endp
Assembly Lesson - October 13, 2005
call
nop
exit
10

Documents pareils