Assembly Language Programming

2y ago
28 Views
2 Downloads
411.59 KB
14 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Luis Waller
Transcription

Assembly Language Programming1

High-level vs. Assembly languageConsider the following statements1.a x y–z2.if x ythen x: x yelse x: x - yHLL (High Level Language) programs are machineindependent. They are easy to learn, easy to use,and convenient for managing complex tasks.Assembly language programs are machinespecific. It is the language that the processor“directly” understands.HLLCompiler2AssemblyLanguage

3

Understanding Assembly LanguageLet us begin with data representation. How torepresent Signed integers Fractions Alphanumeric charactersReview Floating point numbers Pictures?Memory01001011110110101 00 1 1 0 0 00o00Can you readthe contentsof thesememorycells?4

Visualizing instruction execution(The main concept is register-transfer ess-320ALUprocessordataA register is a fast storage within the CPUload x into r1load y into r2a x y - zload z into r0r3 r1 r2r0 r3 – r0store r0 into a5

Assembly language instructions for ahypothetical machine (not MIPS)Load x, r1Load y, r2Load z, r0Add r3, r1, r2Sub r0, r3, r0Store r0, aEach processor has a different set of registers, anddifferent assembly language instructions. The assemblylanguage instructions of Intel Pentium and MIPS arecompletely different.Motorola 68000 has 16 registers r0-r15MIPS has 32 registers r0-r31Pentium has 8 general purpose & 6 segment registers.6

Binary or Machine Language programBoth program and data are representedusingonly 0’s and 1’s inside a computer. Here is asample:031010100011001100 000Loadaddress of xOperationcode031110010Add11r30110r1r2 unusedThese are instruction formats. Each instructionhas a specific format.7

Can we distinguish program from data?ProgramBoth are bit strings.Indistinguishable.DataMEMORYNormally, the programmer has to tell the machine(or use some convention) to specify the address ofthe first instruction. Incorrect specification willlead to errors, and the program is most likely tocrash.8

Bits, bytes, wordsBit:0, 1Byte:string of 8 bits. Each byte has an address.Word:one or more bytes (usually 2 or 4 or 11101167word 0word 100111100000001119

0Word 04Word 18Word 212 Word 3Byte order in a wordBig Endian order[byte 0, byte 1, byte 2, byte 3]Little Endian order[byte 3, byte2, byte 1, byte 0]10

Registers vs. memoryData can be stored in registers or memorylocations. Memory access is slower (takesapproximately 50 ns) than register access (takesapproximately 1 ns or less).To increase the speed of computation it pays tokeep the variables in registers as long as possible.However, due to technology limitations, the numberof registers is quite limited (typically 8-64).MIPS registersMIPS has 32 registers r0-r31. The conventionaluse of these registers is as follows:11

registerassembly name Commentr0 zeroAlways 0r1 atReserved for assemblerr2-r3 v0- v1Stores resultsr4-r7 a0- a3Stores argumentsr8-r15 t0- t7Temporaries, not savedr16-r23 s0- s7Contents saved for later user24-r25 t8- t9More temporaries, not savedr26-r27 k0- k1Reserved by operating systemr28 gpGlobal pointerr29 spStack pointerr30 fpFrame pointerr31 raReturn address12

Example assembly language programsExample 1f g h–iAssume that f, g, h, i are assigned to s0, s1, s2, s3add t0, s1, s2# register t0 contains g hsub s0, t0, s3#f g h–iExample 2.g h A[8]Assume that g, h are in s1, s2. A is an array of words,the elements are stored in consecutive locations of thememory. The base address is stored in s3.lw t0, 32( s3)# t0 gets A[8], 32 4x 8add s1, s2, t0# g h A[8]13

Machine language representationsInstruction “add” belongs to the R-type format.opcodersrtrd6555srcsrcadd s1, s2, t0shift amt function56dstwill be coded as018817655503256The function field is an extension of the opcode, andthey together determine the operation.Note that “sub” has a similar format.14

Assembly language instructions for a hypothetical machine (not MIPS) Load x, r1 Load y, r2 Load z, r0 Add r3, r1, r2 Sub r0, r3, r0 Store r0, a Each processor has a different set of registers, and different assembly language instructions. The assembly language instructions of Intel Pe

Related Documents:

Embedded Systems 1 3-1 8051 Assembly Programming 8051 Programming The 8051 may be programmed using a low-level or a high-level programming language. Low-Level Programming – Assembly language programming writes statements that the microcontroller

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 (e.g. Tasm and Masm) Into executable machine-language programs Assembly Language Tools: Software tools are

Assembly Language Assembly language vs. higher-level language Few, simple types of data Does not specify variable type Simple control flow: goto/jump Assembly language programming is more difficult and error-prone, it is machine-specific; it is longer Assembly language vs. machine

What is Assembly Language? Low-level programming language for a computer One-to-one correspondence with the machine instructions Assembly language is specific to a given processor Assembler: converts assembly program into machine code Assembly language uses: Mnemonics: to represent the names of low-level machine instructions

Tuesday, June 9, 2015 8086 Assembly Language Programming Assembly Language Programming is a low level p

Introduction to Assembly Language Programming. Overview of Assembly Language Advantages: . Slow to development and difficult to debug Basic components in assembly Language: Instruction, Directive, Label, and Comment. 8086/8088 Internal Organisation Temporary Registers ALU Flags EU Contr

assembler Assembly language program ADD r4,r5 compiler to machine for execution However, low-level assembly language is often used for programming directly. We will start from assembly language but use high-level

Chapter 1 provides introduction to the assembly language and gives reasons for programming in the assembly language. Chapter 2 presentsthe basics of computerorganizationwith a focus on three system components: processor, memory, and I/O. Part II is dedicated to Pentium assembly language