Computer Architecture and Assembly Language

Total Page:16

File Type:pdf, Size:1020Kb

Computer Architecture and Assembly Language Computer Architecture and System Programming Laboratory TA Session 1 Data Representation Basics • bit – basic information unit: (1/0) 3 2 1 0 • nibble – sequence of 4 bits: 7 6 5 4 3 2 1 0 • byte – sequence of 8 bits: • word – sequence of 2 (or 4) bytes 16 bit word 32 bit word byte byte byte byte byte byte main memory 64 • address space: 2 -1 0 to 264-1= 0xFFFFFFFFFFFFFFFF … 264 bytes = 24∙260 bytes 2K-1 = 24∙230 Gb = 16 exabytes address … space 1 physical memory 0 Registers file - CPU unit which contains registers general purpose registers r8 – r15 r8d r8w r8b Extended High Low flag register RFLAGS Instruction Pointer register RIP - contains address of the next instruction that is going to be executed (at run time) - changed by unconditional jump, conditional jump, procedure call, and return instructions Note that the list of registers above is partial. The full list can be found here. Assembly Language Program • consists of a series of processor instructions, assembler directives, comments, and data • translated by assembler into machine language instructions (binary code) that can be loaded into memory and executed • NASM - Netwide Assembler - is an assembler and for x86 architecture Example: assembly code: MOV AL, 0x61 ; load AL with 97 decimal (61 hex) machine code (in binary): 10110000 01100001 1011 a binary opcode of instruction 'MOV' 0 specifies if data is byte (‘0’) or full size 16/32 bits (‘1’) 000 a binary identifier for a register 'AL' 01100001 a binary representation of 97 decimal (97d = (int)(97/16)*10 + (97%16 converted to hex digit) = 61h) Basic structure of an assembly instruction label: (pseudo) opcode operands ; comment optional fields either required or forbidden by instruction • each instruction has its address in memory • we mark an instruction with a label to refer it in the code RAM • (non-local) labels have to be unique • an instruction that follows a label can be at the same / next line • colon is optional Examples: … mov ax, 2 ; moves constant 2 to the register ax bytes buffer: resb 64 ; reserves 64 bytes 64 buffer 2048 mov buffer, 2 mov 2048, 2 mov [buffer], 2 mov [2048], 2 mov byte [buffer], 2 mov byte [2048], 2 ☺ move to one starting from buffer numeric byte address in memory value 2 - backslash (\) : if a line ends with backslash, the next line is considered to be a part of the backslash-ended line - no restrictions on white space within a line Instruction Arguments A typical instruction has 2 operands - target operand (left) - source operand (right) 3 kinds of operands exists - immediate : value - register : AX,EBP,DL etc. - memory location : variable or pointer Examples: mov ax, 2 mov [buffer], ax target operand source operand target operand source operand register immediate memory location register ! Note that we cannot have both source and target operands specified as memory locations. mov [var1],[var2] MOV - Move Instruction – copies source to target mov reg8/mem8(16,32,64),reg8/imm8(16,32,64) (copies content of register / immediate (source) to register / memory location (target)) mov reg8(16,32,64),reg8/mem8(16,32,64) (copies content of register / memory location (source) to register (target)) operands have to be of the same size Examples: mov eax, 0x2334AAFF mov [buffer], ax mov word [var], 2 reg32 imm32 mem16 reg16 mem16 imm16 Note that NASM doesn’t remember the size of variables you declare . It will deliberately remember nothing about the symbol var except where it begins, and so you must explicitly code mov word [var], 2. Basic Arithmetical Instruction carry means the digit with <instruction> reg8/mem8(16,32,64),reg8/imm8(16,32,64) promote to higher powers, (source - register / immediate, - register / memory location) whereas borrow means the digit we demote to lower powers <instruction> reg8(16,32,64),reg8/mem8(16,32,64) (source - register / immediate, - register / memory location) ADD - add integers without carry SUB - subtract integers without carry Example: Example: add AX, BX ;(AX gets a value of AX+BX) sub AX, BX ;(AX gets a value of AX-BX) ADC - add integers with carry SBB - subtract with borrow (value of Carry Flag) (value of Carry Flag) Example: Example: adc AX, BX ;(AX gets a value of AX+BX+CF) sbb AX, BX ;(AX gets a value of AX-BX-CF) Basic Arithmetical Instruction <instruction> reg8/mem8(16,32,64) (source / - register / memory location) INC - increment integer Example: inc AX ;(AX gets a value of AX+1) DEC - decrement integer Example: dec byte [buffer] ;(first byte of [buffer] gets a value of first byte of [buffer] -1) Basic Logical Instructions <instruction> reg8/mem8(16,32,64) (source / - register / memory location) NOT – one’s complement negation – inverts all the bits Example: mov al, 11111110b not al ;(AL gets a value of 00000001b) ;(11111110b + 00000001b = 11111111b) NEG – two’s complement negation – inverts all the bits, and adds 1 Example: mov al, 11111110b neg al ;(AL gets a value of not(11111110b)+1=00000001b+1=00000010b) ;(11111110b + 00000010b = 100000000b = 0) Basic Logical Instructions <instruction> reg8/mem8(16,32,64),reg8/imm8(16,32,64) (source - register / immediate, - register / memory location) <instruction> reg8(16,32,64),reg8/mem8(16,32,64) (source - register / immediate, - register / memory location) OR – bitwise or – bit at index i of the gets ‘1’ if bit at index i of source or are ‘1’; otherwise ‘0’ Example: mov al, 11111100 b mov bl, 00000010b or AL, BL ;(AL gets a value 11111110b) AND– bitwise and – bit at index i of the gets ‘1’ if bits at index i of both source and are ‘1’; otherwise ‘0’ Example: or AL, BL ;(with same values of AL and BL as in previous example, AL gets a value 0) CMP – Compare Instruction – compares integers CMP performs a ‘mental’ subtraction - affects the flags as if the subtraction had taken place, but does not store the result of the subtraction. cmp reg8/mem8(16,32,64),reg8/imm8(16,32,64) (source - register / immediate, - register / memory location) cmp reg8(16,32,64),reg8/mem8(16,32,64) (source - register / immediate, - register / memory location) Examples: mov al, 11111100 mov al, 11111100b b mov bl, 11111100 mov bl, 00000010b b cmp al, bl ;(ZF (zero flag) gets a value 0) cmp al, bl ;(ZF (zero flag) gets a value 1) JMP – unconditional jump jmp label JMP tells the processor that the next instruction to be executed is located at the label that is given as part of jmp instruction. Example: this is infinite loop ! mov eax, 1 inc_again: this instruction is never inc eax reached from this code jmp inc_again mov ebx, eax rip register gets inc_again label (address) J<Condition> – conditional jump j<cond> label • execution is transferred to the target instruction only if the specified condition is satisfied • usually, the condition being tested is the result of the last arithmetic or logic operation mov eax, 1 Example: inc_again: inc eax mov eax, 1 cmp eax, 10 inc_again: jne inc_again ; if eax ! = 10, go back to loop inc eax cmp eax, 10 je end_of_loop ; if eax = = 10, jump to end_of_loop jmp inc_again ; go back to loop end_of_loop: Instruction Description Flags JO Jump if overflow OF = 1 JNO Jump if not overflow OF = 0 JS Jump if sign SF = 1 JNS Jump if not sign SF = 0 JE Jump if equal ZF = 1 JZ Jump if zero JNE Jump if not equal ZF = 0 JNZ Jump if not zero JB Jump if below CF = 1 JNAE Jump if not above or equal JC Jump if carry JNB Jump if not below CF = 0 JAE Jump if above or equal JNC Jump if not carry JBE Jump if below or equal CF = 1 or ZF = 1 JNA Jump if not above JA Jump if above CF = 0 and ZF = 0 JNBE Jump if not below or equal JL Jump if less SF <> OF JNGE Jump if not greater or equal JGE Jump if greater or equal SF = OF JNL Jump if not less JLE Jump if less or equal ZF = 1 or SF <> OF JNG Jump if not greater JG Jump if greater ZF = 0 and SF = OF JNLE Jump if not less or equal JP Jump if parity PF = 1 JPE Jump if parity even JNP Jump if not parity PF = 0 JPO Jump if parity odd JCXZ Jump if CX register is 0 CX = 0 JECXZ Jump if ECX register is 0 ECX = 0 Note that the list above is partial. The full list can be found here. d<size> – declare initialized data d<size> initial value Pseudo-instruction <size> filed <size> value DB byte 1 byte DW word 2 bytes DD double word 4 bytes DQ quadword 8 bytes DT tenbyte 10 bytes DDQ double quadword 16 bytes DO octoword 16 bytes Examples: var: db 0x55 ; define a variable var of size byte, initialized by 0x55 var: db 0x55,0x56,0x57 ; three bytes in succession var: db 'a‘ ; character constant 0x61 (ascii code of ‘a’) var: db 'hello’,10 ; string constant var: dw 0x1234 ; 0x34 0x12 var: dw ‘A' ; 0x41 0x00 – complete to word var: dw ‘ABC' ; 0x41 0x42 0x43 0x00 – complete to word var: dd 0x12345678 ; 0x78 0x56 0x34 0x12 Assignment 0 You get a simple program that receives a string from the user. Than, it calls to a function (that you’ll implement in assembly) that receives one string as an argument and should do the following: • Convert lower case to upper case. • Convert ‘(’ into ‘<’. • Convert ‘)’ into ‘>’. • Count the number of the non-letter characters, that is ANY character that is not 'a'->'z' or 'A'->'Z‘, including ‘\n’ character The function shall return the number of the letter characters in the string.
Recommended publications
  • 2. Assembly Language Assembly Language Is a Programming Language That Is Very Similar to Machine Language, but Uses Symbols Instead of Binary Numbers
    2. Assembly Language Assembly Language is a programming language that is very similar to machine language, but uses symbols instead of binary numbers. It is converted by the assembler into executable machine- language programs. Assembly language is machine-dependent; an assembly program can only be executed on a particular machine. 2.1 Introduction to Assembly Language Tools Practical assembly language programs can, in general, be written using one of the two following methods: 1- The full-segment definition form 2- The simplified segment definition form In both methods, the source program includes two types of instructions: real instructions, and pseudo instructions. Real instructions such as MOV and ADD are the actual instructions that are translated by the assembler into machine code for execution by the CPU. Pseudo instructions, on the other hand, don’t generate machine code and are only used to give directions to the assembler about how it should translate the assembly language instructions into machine code. The assembler program converts the written assembly language file (called source file) into machine code file (called object file). Another program, known as the linker, converts the object file into an executable file for practical run. It also generates a special file called the map file which is used to get the offset addresses of the segments in the main assembly program as shown in figure 1. Other tools needed in assembling coding include a debugger, and an editor as shown in figure 2 Figure 2. Program Development Procedure There are several commercial assemblers available like the Microsoft Macro Assembler (MASM), and the Borland Turbo Assembler (TASM).
    [Show full text]
  • NASM – the Netwide Assembler
    NASM – The Netwide Assembler version 2.14rc7 © 1996−2017 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive. Contents Chapter 1: Introduction . 17 1.1 What Is NASM?. 17 1.1.1 License Conditions . 17 Chapter 2: Running NASM . 19 2.1 NASM Command−Line Syntax . 19 2.1.1 The −o Option: Specifying the Output File Name . 19 2.1.2 The −f Option: Specifying the Output File Format . 20 2.1.3 The −l Option: Generating a Listing File . 20 2.1.4 The −M Option: Generate Makefile Dependencies. 20 2.1.5 The −MG Option: Generate Makefile Dependencies . 20 2.1.6 The −MF Option: Set Makefile Dependency File. 20 2.1.7 The −MD Option: Assemble and Generate Dependencies . 20 2.1.8 The −MT Option: Dependency Target Name . 21 2.1.9 The −MQ Option: Dependency Target Name (Quoted) . 21 2.1.10 The −MP Option: Emit phony targets . 21 2.1.11 The −MW Option: Watcom Make quoting style . 21 2.1.12 The −F Option: Selecting a Debug Information Format . 21 2.1.13 The −g Option: Enabling Debug Information. 21 2.1.14 The −X Option: Selecting an Error Reporting Format . 21 2.1.15 The −Z Option: Send Errors to a File. 22 2.1.16 The −s Option: Send Errors to stdout ..........................22 2.1.17 The −i Option: Include File Search Directories . 22 2.1.18 The −p Option: Pre−Include a File . 22 2.1.19 The −d Option: Pre−Define a Macro .
    [Show full text]
  • NASM — the Netwide Assembler Version 2.09.04
    NASM — The Netwide Assembler version 2.09.04 -~~..~:#;L .-:#;L,.- .~:#:;.T -~~.~:;. .~:;. E8+U *T +U' *T# .97 *L E8+' *;T' *;, D97 `*L .97 '*L "T;E+:, D9 *L *L H7 I# T7 I# "*:. H7 I# I# U: :8 *#+ , :8 T, 79 U: :8 :8 ,#B. .IE, "T;E* .IE, J *+;#:T*" ,#B. .IE, .IE, © 1996−2010 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive. Contents Chapter 1: Introduction . .15 1.1 What Is NASM? . .15 1.1.1 Why Yet Another Assembler?. .15 1.1.2 License Conditions . .15 1.2 Contact Information . .16 1.3 Installation. .16 1.3.1 Installing NASM under MS−DOS or Windows . .16 1.3.2 Installing NASM under Unix . .17 Chapter 2: Running NASM . .18 2.1 NASM Command−Line Syntax . .18 2.1.1 The −o Option: Specifying the Output File Name . .18 2.1.2 The −f Option: Specifying the Output File Format . .19 2.1.3 The −l Option: Generating a Listing File . .19 2.1.4 The −M Option: Generate Makefile Dependencies . .19 2.1.5 The −MG Option: Generate Makefile Dependencies . .19 2.1.6 The −MF Option: Set Makefile Dependency File . .19 2.1.7 The −MD Option: Assemble and Generate Dependencies. .19 2.1.8 The −MT Option: Dependency Target Name. .20 2.1.9 The −MQ Option: Dependency Target Name (Quoted) . .20 2.1.10 The −MP Option: Emit phony targets. .20 2.1.11 The −F Option: Selecting a Debug Information Format .
    [Show full text]
  • Linux Assembly HOWTO Linux Assembly HOWTO
    Linux Assembly HOWTO Linux Assembly HOWTO Table of Contents Linux Assembly HOWTO..................................................................................................................................1 Konstantin Boldyshev and François−René Rideau................................................................................1 1.INTRODUCTION................................................................................................................................1 2.DO YOU NEED ASSEMBLY?...........................................................................................................1 3.ASSEMBLERS.....................................................................................................................................1 4.METAPROGRAMMING/MACROPROCESSING............................................................................2 5.CALLING CONVENTIONS................................................................................................................2 6.QUICK START....................................................................................................................................2 7.RESOURCES.......................................................................................................................................2 1. INTRODUCTION...............................................................................................................................2 1.1 Legal Blurb........................................................................................................................................2
    [Show full text]
  • Different Emulators to Write 8086 Assembly Language Programs
    Different Emulators to write 8086 assembly language programs Subject: IWM Content • Emu8086 • TASM(Turbo Assembler) • MASM(Microsoft Macro Assembler) • NASM(Netwide Assembler) • FASM(Flat Assembler) Emu8086 • Emu8086 combines an advanced source editor, assembler, disassembler, software emulator with debugger, and step by step tutorials • It permit to assemble, emulate and debug 8086 programs. • This emulator was made for Windows, it works fine on GNU/Linux (with the help of Wine). • The source code is compiled by assembler and then executed on Emulator step-by-step, allowing to watch registers, flags and memory while program runs. how to run program on Emu8086 • Download Emu8086 through this link : https://download.cnet.com/Emu8086-Microprocessor- Emulator/3000-2069_4-10392690.html • Start Emu8086 by running Emu8086.exe • Select “Examples" from "File" menu. • Click “Emulate” button (or press F5). • Click “Single Step” button (or press F8) and watch how the code is being executed. Turbo Assembler(Tasm) • Turbo Assembler (TASM) is a computer assembler developed by Borland which runs on and produces code for 16- or 32-bit x86 DOS or Microsoft Windows. • The Turbo Assembler package is bundled with the Turbo Linker, and is interoperable with the Turbo Debugger. • Turbo Assembler (TASM) a small 16-bit computer program which enables us to write 16 bit i.e. x86 programming code on 32-bit machine. It can be used with any high level language compliers like GCC compiler set to build object files. So that programmers can use their daily routine machines to write 16-bit code and execute on x86 devices. how to run program using TASM • Download TASM through this link : https://techapple.net/2013/01/tasm-windows-7-windows-8-full- screen-64bit-version-single-installer/ • Start TASM by running tasm.exe • It will open DOSBOX.
    [Show full text]
  • Internals of the Netwide Assembler ======
    Internals of the Netwide Assembler ================================== The Netwide Assembler is intended to be a modular, re-usable x86 assembler, which can be embedded in other programs, for example as the back end to a compiler. The assembler is composed of modules. The interfaces between them look like: +--- preproc.c ----+ | | +---- parser.c ----+ | | | | float.c | | | +--- assemble.c ---+ | | | nasm.c ---+ insnsa.c +--- nasmlib.c | | +--- listing.c ----+ | | +---- labels.c ----+ | | +--- outform.c ----+ | | +----- *out.c -----+ In other words, each of `preproc.c', `parser.c', `assemble.c', `labels.c', `listing.c', `outform.c' and each of the output format modules `*out.c' are independent modules, which do not directly inter-communicate except through the main program. The Netwide *Disassembler* is not intended to be particularly portable or reusable or anything, however. So I won't bother documenting it here. :-) nasmlib.c --------- This is a library module; it contains simple library routines which may be referenced by all other modules. Among these are a set of wrappers around the standard `malloc' routines, which will report a fatal error if they run out of memory, rather than returning NULL. preproc.c --------- This contains a macro preprocessor, which takes a file name as input and returns a sequence of preprocessed source lines. The only symbol exported from the module is `nasmpp', which is a data structure of type `Preproc', declared in nasm.h. This structure contains pointers to all the functions designed to be callable from outside the module. parser.c -------- This contains a source-line parser. It parses `canonical' assembly source lines, containing some combination of the `label', `opcode', `operand' and `comment' fields: it does not process directives or macros.
    [Show full text]
  • Lab # 1 Introduction to Assembly Language
    Assembly Language LAB Islamic University – Gaza Engineering Faculty Department of Computer Engineering 2013 ECOM 2125: Assembly Language LAB Eng. Ahmed M. Ayash Lab # 1 Introduction to Assembly Language February 11, 2013 Objective: To be familiar with Assembly Language. 1. Introduction: Machine language (computer's native 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 Machine language can be made directly from java code using interpreter. The difference between compiling and interpreting is as follows. Compiling translates the high-level code into a target language code as a single unit. Interpreting translates the individual steps in a high-level program one at a time rather than the whole program as a single unit. Each step is executed immediately after it is translated. C, C++ code is executed faster than Java code, because they transferred to assembly language before machine language. 1 Using Visual Studio 2012 to convert C++ program to assembly language: - From File menu >> choose new >> then choose project. Or from the start page choose new project. - Then the new project window will appear, - choose visual C++ and win32 console application - The project name is welcome: This is a C++ Program that print "Welcome all to our assembly Lab 2013” 2 To run the project, do the following two steps in order: 1. From build menu choose build Welcome. 2. From debug menu choose start without debugging. The output is To convert C++ code to Assembly code we follow these steps: 1) 2) 3 3) We will find the Assembly code on the project folder we save in (Visual Studio 2012\Projects\Welcome\Welcome\Debug), named as Welcome.asm Part of the code: 2.
    [Show full text]
  • Intel X86 Assembly Language & Microarchitecture
    Intel x86 Assembly Language & Microarchitecture #x86 Table of Contents About 1 Chapter 1: Getting started with Intel x86 Assembly Language & Microarchitecture 2 Remarks 2 Examples 2 x86 Assembly Language 2 x86 Linux Hello World Example 3 Chapter 2: Assemblers 6 Examples 6 Microsoft Assembler - MASM 6 Intel Assembler 6 AT&T assembler - as 7 Borland's Turbo Assembler - TASM 7 GNU assembler - gas 7 Netwide Assembler - NASM 8 Yet Another Assembler - YASM 9 Chapter 3: Calling Conventions 10 Remarks 10 Resources 10 Examples 10 32-bit cdecl 10 Parameters 10 Return Value 11 Saved and Clobbered Registers 11 64-bit System V 11 Parameters 11 Return Value 11 Saved and Clobbered Registers 11 32-bit stdcall 12 Parameters 12 Return Value 12 Saved and Clobbered Registers 12 32-bit, cdecl — Dealing with Integers 12 As parameters (8, 16, 32 bits) 12 As parameters (64 bits) 12 As return value 13 32-bit, cdecl — Dealing with Floating Point 14 As parameters (float, double) 14 As parameters (long double) 14 As return value 15 64-bit Windows 15 Parameters 15 Return Value 16 Saved and Clobbered Registers 16 Stack alignment 16 32-bit, cdecl — Dealing with Structs 16 Padding 16 As parameters (pass by reference) 17 As parameters (pass by value) 17 As return value 17 Chapter 4: Control Flow 19 Examples 19 Unconditional jumps 19 Relative near jumps 19 Absolute indirect near jumps 19 Absolute far jumps 19 Absolute indirect far jumps 20 Missing jumps 20 Testing conditions 20 Flags 21 Non-destructive tests 21 Signed and unsigned tests 22 Conditional jumps 22 Synonyms and terminology 22 Equality 22 Greater than 23 Less than 24 Specific flags 24 One more conditional jump (extra one) 25 Test arithmetic relations 25 Unsigned integers 25 Signed integers 26 a_label 26 Synonyms 27 Signed unsigned companion codes 27 Chapter 5: Converting decimal strings to integers 28 Remarks 28 Examples 28 IA-32 assembly, GAS, cdecl calling convention 28 MS-DOS, TASM/MASM function to read a 16-bit unsigned integer 29 Read a 16-bit unsigned integer from input.
    [Show full text]
  • Assembly Language Tutorial
    Assembly Language Tutorial ASSEMBLY LANGUAGE TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Assembly Programming Tutorial Assembly language is a low-level programming language for a computer, or other programmable device specific to a particular computer architecture in contrast to most high- level programming languages, which are generally portable across multiple systems. Assembly language is converted into executable machine code by a utility program referred to as an assembler like NASM, MASM etc. Audience This tutorial has been designed for software programmers with a need to understand the Assembly programming language starting from scratch. This tutorial will give you enough understanding on Assembly programming language from where you can take yourself at higher level of expertise. Prerequisites Before proceeding with this tutorial you should have a basic understanding of Computer Programming terminologies. A basic understanding of any of the programming languages will help you in understanding the Assembly programming concepts and move fast on the learning track. TUTORIALS POINT Simply Easy Learning Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] TUTORIALS POINT Simply Easy Learning Table of Content Assembly Programming Tutorial .............................................
    [Show full text]
  • Procedure to Create and Execute a Simple Assembly Program on Ubuntu (Linux) Using Nasm
    Procedure to create and execute a simple assembly program on Ubuntu (Linux) using nasm Environment - Core 2 duo/i3/i5/i7 - 64bit processor OS – ubuntu 32bit/64bit OS Assembler used –nasm (the netwide assembler NASM is portable, free and powerful Editor Used – gedit Steps to follow - 1. Boot the machine with ubuntu 2. Select and click on <dash home> icon from the toolbar. 3. Start typing “terminal” . Different terminal windows available will be displayed. 4. Click on “terminal” icon. A terminal window will open showing command prompt. 5. Give the following command at the prompt to invoke the editor gedit hello.asm 6. Type in the program in gedit window, save and exit 7. To assemble the program write the command at the prompt as follows and press enter key nasm –f elf32 hello.asm –o hello.o (for 32 bit) nasm –f elf64 hello.asm –o hello.o (for 64 bit) 8. If the execution is error free, it implies hello.o object file has been created. 9. To link and create the executable give the command as ld –o hello hello.o 10. To execute the program write at the prompt ./hello 11. “hello world” will be displayed at the prompt The assembly program structure - The assembly program can be divided into three sections: The .data section This section is for "declaring initialized data", in other words defining "variables" that already contain stuff. However this data does not change at runtime so they're not really variables. The .data section is used for things like filenames and buffer sizes, and you can also define constants using the EQU instruction.
    [Show full text]
  • The Netwide Assembler
    NASM – The Netwide Assembler version 2.14.03rc2 © 1996−2017 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive. Contents Chapter 1: Introduction . 17 1.1 What Is NASM?. 17 1.1.1 License Conditions . 17 Chapter 2: Running NASM . 19 2.1 NASM Command−Line Syntax . 19 2.1.1 The −o Option: Specifying the Output File Name . 19 2.1.2 The −f Option: Specifying the Output File Format . 20 2.1.3 The −l Option: Generating a Listing File . 20 2.1.4 The −M Option: Generate Makefile Dependencies. 20 2.1.5 The −MG Option: Generate Makefile Dependencies . 20 2.1.6 The −MF Option: Set Makefile Dependency File. 20 2.1.7 The −MD Option: Assemble and Generate Dependencies . 20 2.1.8 The −MT Option: Dependency Target Name . 21 2.1.9 The −MQ Option: Dependency Target Name (Quoted) . 21 2.1.10 The −MP Option: Emit phony targets . 21 2.1.11 The −MW Option: Watcom Make quoting style . 21 2.1.12 The −F Option: Selecting a Debug Information Format . 21 2.1.13 The −g Option: Enabling Debug Information. 21 2.1.14 The −X Option: Selecting an Error Reporting Format . 21 2.1.15 The −Z Option: Send Errors to a File. 22 2.1.16 The −s Option: Send Errors to stdout ..........................22 2.1.17 The −i Option: Include File Search Directories . 22 2.1.18 The −p Option: Pre−Include a File .
    [Show full text]
  • PC Assembly Language
    PC Assembly Language Paul A. Carter August 25, 2002 Copyright c 2001, 2002 by Paul Carter This may be reproduced and distributed in its entirety (including this au- thorship, copyright and permission notice), provided that no charge is made for the document itself, without the author’s consent. This includes “fair use” excerpts like reviews and advertising, and derivative works like trans- lations. Note that this restriction is not intended to prohibit charging for the service of printing or copying the document. Instructors are encouraged to use this document as a class resource; however, the author would appreciate being notified in this case. Contents Preface iii 1 Introduction 1 1.1 Number Systems . 1 1.1.1 Decimal . 1 1.1.2 Binary . 1 1.1.3 Hexadecimal . 3 1.2 Computer Organization . 4 1.2.1 Memory . 4 1.2.2 The CPU . 5 1.2.3 The 80x86 family of CPUs . 5 1.2.4 8086 16-bit Registers . 6 1.2.5 80386 32-bit registers . 7 1.2.6 Real Mode . 8 1.2.7 16-bit Protected Mode . 8 1.2.8 32-bit Protected Mode . 9 1.2.9 Interrupts . 10 1.3 Assembly Language . 10 1.3.1 Machine language . 10 1.3.2 Assembly language . 11 1.3.3 Instruction operands . 11 1.3.4 Basic instructions . 12 1.3.5 Directives . 13 1.3.6 Input and Output . 15 1.3.7 Debugging . 16 1.4 Creating a Program . 17 1.4.1 First program . 18 1.4.2 Compiler dependencies .
    [Show full text]