18
Assembly Disc Eng Alaa.I.Haniya

Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

  • Upload
    vungoc

  • View
    231

  • Download
    6

Embed Size (px)

Citation preview

Page 1: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Assembly Disc

Eng Alaa.I.Haniya

Page 2: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Assembly and Machine Language

Machine language Native to a processor: executed directly by hardware

Instructions consist of binary code: 1s and 0s

Assembly language

Slightly higher-level language Readability of instructions is better than machine language

Page 3: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Assembly and Machine Language

Assemblers translate assembly to machine code

Compilers translate high-level programs to machine code

Either directly, or Indirectly via an assembler

Page 4: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Compiler and Assembler

Page 5: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Faster

Easier

Portable.

So

Why Learn Assembly Language?

Advantages of High-Level

Languages

Page 6: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Programs in high level language are portable; However,

Assembly language programs are not portable.

A portable application (portable app), sometimes also called standalone, is a computer program designed to run independently from an operating system.

Portable versions of applications can usually also be used instead of the normal installable version, which some users find useful

Page 7: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

• Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit (CPU).

• Instructions consist of binary code: 1s and 0s

• An assembly language: is a low-level programming language that is very similar to machine language, but uses symbols instead of binary numbers.

• Slightly higher-level language

Basic Concepts

Page 8: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

An assembler is a program that converts source-code programs written in assembly language into object files in machine language.

Assembler Examples:

• MASM (Macro Assembler from Microsoft),

• TASM (Turbo Assembler from Borland)

• NASM (Netwide Assembler for both Windows and Linux),

Basic Concepts

Page 9: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

A linker is a program that combines individual files created by an assembler into a single executable program .

A debugger is a program that allows you to trace the execution of a program and examine the content of registers and memory.

Compilers translate high-level programs to machine code either directly or indirectly via an assembler.

Basic Concepts

Page 10: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler
Page 11: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Storage Sizes

Integer Storage Sizes

Standard sizes:

byte 8

word 16

doubleword 32

quadword 64

What is the largest unsigned integer that may be stored in 20 bits?

Page 12: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Ranges of Signed Integers

The unsigned range is divided into two signed ranges for positive

and negative numbers

Practice: What is the range of signed values that may be stored in 20 bits?

Page 13: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Carry and Overflow

Overflow occurs when

Adding two positive numbers and the sum is negative

Adding two negative numbers and the sum is positive

Can happen because of the fixed number of sum bits

Page 14: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Carry and Overflow Examples

We can have carry without overflow and vice-versa

Four cases are possible

1

1

1

1

1

1

0

0

0

0

1

1

1

1

15

0

0

0

0

1

1

1

1

15 +

+ 0

0

0

0

1

0

0

0

8

1

1

1

1

1

0

0

0

245 (-8)

0

0

0

1

0

1

1

1

23

0

0

0

0

0

1

1

1

7

Carry = 0 Overflow = 0

Carry = 1 Overflow = 0

1

1

1

1

0

1

0

0

1

1

1

1

79

1

1

0

1

1

0

1

0

218 (-38) +

+ 0

1

0

0

0

0

0

0

64

1

0

0

1

1

1

0

1

157 (-99)

1

0

0

0

1

1

1

1

143

0

1

1

1

0

1

1

1

119 (-113)

Carry = 0 Overflow = 1

Carry = 1 Overflow = 1

Page 15: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Character Storage

• Standard ASCII: 7-bit character codes (0 – 127)

• Extended ASCII: 8-bit character codes (0 – 255)

Page 16: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

ASCII code

ASCII code for space character ? = 20 H= 32 D. ASCII code for 'L' ? 4C H= 76 D. ASCII code for 'a' ? 61 H= 97 D

Page 17: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

Control character codes = 00 to 1F (hex)

Examples of Control Characters

• Character 0 is the NULL character, used to terminate a string

• Character 9 is the Horizontal Tab (HT) character

• Character 0A (hex) = 10 (decimal) is the Line Feed (LF)

• Character 0D (hex) = 13 (decimal) is the Carriage Return (CR)

• The LF and CR characters are used together , they advance the cursor to the beginning of next line

Control Characters

Page 18: Assembly lab lab1 - site.iugaza.edu.pssite.iugaza.edu.ps/ahaniya/files/ass.disc1_.pdfNative to a processor: ... programs written in assembly language into object files in ... Assembler

What is the largest value you can represent using a 256-bit unsigned integer?

Sol: (2^ 256)-1

What is the largest positive value you can represent using a 256-bit signed integer?

Sol: + 2255-1

Question