1 / 14

CET 3510 - Microcomputer Systems Technology Lecture 7 – Real Assembly

CET 3510 - Microcomputer Systems Technology Lecture 7 – Real Assembly. Dr. José M. Reyes Álamo. High Level Assembly (HLA). 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

thora
Download Presentation

CET 3510 - Microcomputer Systems Technology Lecture 7 – Real Assembly

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. CET 3510 - Microcomputer Systems TechnologyLecture 7 – Real Assembly Dr. José M. Reyes Álamo

  2. High Level Assembly (HLA) • 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

  3. Differences between HLA and Real Assembly • 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.

  4. C Language and Assembly • 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)

  5. Example 1 main() { int x = 5; } Assembly: .file "cases.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $5, -4(%ebp) leave ret .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits C Assembly

  6. Example 2 main() { int x = 5; if(x < 0) { x++; } } .file "cases.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $5, -4(%ebp) cmpl $0, -4(%ebp) jns .L4 addl $1, -4(%ebp) .L4: leave ret .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits C Assembly

  7. Example 3 main() { int x = 5; if(x < 0) { x++; } else { x--; } } .file "cases.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $5, -4(%ebp) cmpl $0, -4(%ebp) jns .L2 addl $1, -4(%ebp) jmp .L5 .L2: subl $1, -4(%ebp) .L5: leave ret .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits C Assembly

  8. Example 4 main() { int x = 5; while (x < 10){ x++; } } .file "cases.c" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $5, -4(%ebp) jmp .L2 .L3: addl $1, -4(%ebp) .L2: cmpl $9, -4(%ebp) jle .L3 leave ret .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits C Assembly

  9. Example 5 #include<stdio.h> main() { printf("Hello World \n"); } .file "cases.c" .section .rodata .LC0: .string "Hello World " .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts leave ret .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5" .section .note.GNU-stack,"",@progbits C Assembly

  10. Experiment • 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

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

  12. ReviewforMidterm • 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

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

  14. ReviewforMidterm • Logical Operations • AND • NOT • OR • XOR • How to use these to manipulate, insert and clear bits

More Related