14
CET 3510 - Microcomputer Systems Technology Lecture 7 – Real Assembly Dr. José M. Reyes Álamo 1

Dr. José M. Reyes Álamo 1. An assembly language that is easier to understand that regular assembly Borrow some features from high-level languages

Embed Size (px)

Citation preview

Page 1: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

CET 3510 - Microcomputer Systems Technology

Lecture 7 – Real AssemblyDr. José M. Reyes Álamo

1

Page 2: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

An assembly language that is easier to understand that regular assembly

Borrow some features from high-level languages without being a high-level programming language

Supported in multiple platforms

2

High Level Assembly (HLA)

Page 3: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

No “sugary” commands such as if, while, for .

Only jump statements and labels are available to do decisions and loops.

It is understood by the processor. Programs execute faster but are harder to

write.

Differences between HLA and Real Assembly

Page 4: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Under Linux, to compile a C program into assembly use the following command:◦ gcc –S myProgram.c

The gcc compiler works for both C programs (extension .c) and assembly programs (extension .s)

C Language and Assembly

Page 5: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Example 1

C Assembly

main(){ int x = 5;}

Assembly:.file "cases.c".text

.globl main.type main, @function

main:pushl %ebpmovl %esp, %ebpsubl $16, %espmovl $5, -4(%ebp)leaveret.size main, .-main.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".section .note.GNU-stack,"",@progbits

Page 6: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Example 2

C Assembly

main(){ int x = 5; if(x < 0) { x++; }}

.file "cases.c"

.text.globl main

.type main, @functionmain:

pushl %ebpmovl %esp, %ebpsubl $16, %espmovl $5, -4(%ebp)cmpl $0, -4(%ebp)jns .L4addl $1, -4(%ebp)

.L4:leaveret.size main, .-main.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".section .note.GNU-stack,"",@progbits

Page 7: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Example 3

C Assembly

main(){ int x = 5; if(x < 0) { x++; } else { x--; }}

.file "cases.c".text

.globl main.type main, @function

main:pushl %ebpmovl %esp, %ebpsubl $16, %espmovl $5, -4(%ebp)cmpl $0, -4(%ebp)jns .L2addl $1, -4(%ebp)jmp .L5

.L2:subl $1, -4(%ebp)

.L5:leaveret.size main, .-main.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".section .note.GNU-stack,"",@progbits

Page 8: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Example 4

C Assembly

main(){ int x = 5; while (x < 10){ x++; }}

.file "cases.c"

.text.globl main

.type main, @functionmain:

pushl %ebpmovl %esp, %ebpsubl $16, %espmovl $5, -4(%ebp)jmp .L2

.L3:addl $1, -4(%ebp)

.L2:cmpl $9, -4(%ebp)jle .L3leaveret.size main, .-main.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".section .note.GNU-stack,"",@progbits

Page 9: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Example 5

C Assembly

#include<stdio.h> main(){ printf("Hello World \n");}

.file "cases.c"

.section .rodata.LC0:

.string "Hello World "

.text.globl main

.type main, @functionmain:

pushl %ebpmovl %esp, %ebpandl $-16, %espsubl $16, %espmovl $.LC0, (%esp)call putsleaveret.size main, .-main.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5".section .note.GNU-stack,"",@progbits

Page 10: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Write a few simple programs C programs Write the same program in HLA Compile the C program into Real Assembly

gcc –S myProgram.c Compare all 3 Try to understand especially how C code is

translated to Assembly

Experiment

Page 11: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Computer and Processor Architecture:◦ Components of computers◦ Memory limits, register size etc.◦ Data organizations (bits, nibble, word, etc.)

Review for Midterm

Page 12: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

HLA Syntax:◦ Commands◦ Data types◦ Standard libraries (stdlib.hhf)◦ Differences with Real Assembly Language◦ Differences with High-Level programming

languages such as C++◦ Be able to read and write HLA code◦ Labels and jumps

Review for Midterm

Page 13: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Number Systems (Binary, Decimal, Hexadecimal) Arithmetic◦ Conversion to/from different bases◦ Two’s complement binary◦ Representation in Hex

Review for Midterm

Page 14: Dr. José M. Reyes Álamo 1.  An assembly language that is easier to understand that regular assembly  Borrow some features from high-level languages

Logical Operations◦ AND◦ NOT◦ OR◦ XOR◦ How to use these to manipulate, insert and clear

bits

Review for Midterm