Coding.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 5th Edition
CS2422 Assembly Language and System Programming Assembly Language Fundamentals Department of Computer Science National Tsing Hua University.
Department of Computer Science and Software Engineering
Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
Assembly Language Procedures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Symbolic Constants Equal-Sign Directive Calculating.
Runtime Stack Managed by the CPU, using two registers
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Intrinsic Data Types (1 of 2) BYTE, SBYTE 8-bit unsigned.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language and System Programming Procedures Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Kip Irvine: Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language & System Programming October 24, 2006.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
CS2422 Assembly Language & System Programming September 26, 2006.
Sahar Mosleh California State University San MarcosPage 1 Applications of Shift and Rotate Instructions.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Chapter 3: Assembly Language Fundamentals
Assembly Language for x86 Processors 7th Edition
Assembly Language for x86 Processors 6th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
Assembly Language for x86 Processors 6th Edition Chapter 4: Data-Related Operators and Directives, Addressing Modes (c) Pearson Education, All rights.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Functions available for Writing to the Video Display Three different ways to write to the display –Irvine library functions –DOS Video Functions (Interrupt.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.
Sahar Mosleh California State University San MarcosPage 1 Introduction to Assembly language Data Definition Reserve words Labels Instruction Mnemonic Hello.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CHAPTER 5: PROCEDURES ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Procedure Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/27 with slides by Kip Irvine.
Assembly Language for x86 Processors 6th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You may modify.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
CS2422 Assembly Language and System Programming 0 Week 7 & 8 Intro. To Assembly Programming.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
3/10/2003 Lecture 9: Procedures Assembly Language for Intel-Based Computers 4th edition Kip R. Irvine.
Assembly Language for x86 Processors 6th Edition
Assembly Language for x86 Processors 6th Edition
Assembly Language for x86 Processors 7th Edition
Chapter 5: Procedures.
Assembly Lab 3.
x86 Assembly Language Fundamentals
Assembly Language Fundamentals
Assembly Language Lab (4).
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 4: Instructions
Data-Related Operators and Directives
Data Transfers, Addressing, and Arithmetic
Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 4th Edition
The Stack and Procedures
Hardware & Software Architecture
MUL operation.
More on operators and procedures in the Linked
Presentation transcript:

Coding

MOVZX INCLUDE Irvine32.inc .data Uarray WORD 1000h,2000h,3000h,4000h .code main PROC ; Move with zero extension: movzx eax,Uarray movzx ebx,Uarray+2 movzx ecx,Uarray+4 movzx edx,Uarray+6 call DumpRegs exit main ENDP END main

MOVSX INCLUDE Irvine32.inc .data Sarray SWORD -1,-2,-3,-4 .code main PROC ; Move with sign extension: ;movsx eax,Sarray ;movsx ebx,Sarray+2 ;movsx ecx,Sarray+4 ;movsx edx,Sarray+6 call DumpRegs exit main ENDP END main

INCLUDE irvine32.inc .code main PROC mov ax,15 ; start ax=15 LOOP INCLUDE irvine32.inc .code main PROC mov ax,15 ; start ax=15 call DumpRegs mov ecx,6 ; set start ecx = 6 L1: ; L1 = destination dec ax loop L1 exit main ENDP END main

mov ecx, 6 ;loop ecx = 7 times ..6 5 4 3 2 1 0 call DumpRegs L2: INCLUDE Irvine32.inc .code main PROC mov eax, 1 ;start eax=1 mov ebx, 1 ;ebx = 1 mov edx, 10 ;edx = 10 mov ecx, 6 ;loop ecx = 7 times ..6 5 4 3 2 1 0 call DumpRegs L2: inc ebx dec edx add eax, 1 ; add value in eax + 1 loop L2 exit main ENDP END main LOOP

Color TITLE Chapter 5 Exercise 1 (ch05_01.asm) Comment @ Description: Write a program that displays the same string in four different colors, using a loop. Call the SetTextColor procedure from the book's link library. Any colors may be chosen, but you may find it easiest to change the foreground color.

INCLUDE Irvine32.inc .data str1 BYTE "This line is displayed in color",0 .code main PROC mov eax, white + (green * 16) ; white on green backgrouund mov ecx,4 ; loop counter L1: call SetTextColor mov edx,OFFSET str1 call WriteString call Crlf add eax,2 ; add 2 to foreground color loop L1 exit main ENDP END main

Print output to screen INCLUDE Irvine32.inc .code main PROC mov eax,1234h ; input argument call WriteHex ; show hex number call Crlf ; end of line ; no call DumpRegs bcoz no register to be display exit main ENDP END main

Clear screen before print output INCLUDE Irvine32.inc .code main PROC call Clrscr ; clear screen first mov eax,15 ; eax = 0000000F call Delay call DumpRegs exit main ENDP END main

; Display a null-terminated string and ; move the cursor to the beginning of the next screen line. INCLUDE Irvine32.inc .data str1 BYTE "Assembly language is easy!",0 .code main PROC mov edx,OFFSET str1 call WriteString call Crlf exit main ENDP END main

;Display a null-terminated string and ;move the cursor to the beginning of the next screen line (use embedded CR/LF) INCLUDE Irvine32.inc .data str1 BYTE "Assembly language is easy!",0Dh,0Ah,0 str2 BYTE "I like Assembly language!",0Dh,0Ah,0 .code main PROC mov edx,OFFSET str1 call WriteString call Crlf mov edx,OFFSET str2 exit main ENDP END main

Display an unsigned integer in binary, decimal, and hexadecimal, each on a separate line. INCLUDE Irvine32.inc .data IntVal = 35 .code main PROC mov eax,IntVal call WriteBin ; display binary call Crlf call WriteDec ; display decimal call WriteHex ; display hexadecimal exit main ENDP END main

Assignment 1 USAGE of LIBRARY PROCEDURE Display a null-terminated string and move the cursor to the beginning of the next screen line (use embedded CR/LF) for the following strings USAGE of LIBRARY PROCEDURE Clrscr - Clears console, locates cursor at upper left corner DumpRegs – Displays general-purpose registers and flags (hex) WriteChar - Writes a single character to standard output WriteHex - Writes an unsigned 32-bit integer in hexadecimal format SetTextColor - Sets foreground and background colors of all subsequent console text output

Assignment 2 Write a program to display a null-terminated string and move the cursor to the beginning of the next screen line (use embedded CR/LF) as the following output. Before proceed to next string, display an unsigned integer 85 in binary, decimal, and hexadecimal, each on a separate line. Please refer the following output.

Use the following variable definition for the remaining questions in this section: .data MyByte SBYTE -4,-2,3,1 MyWord WORD 1000h,2000h,3000h,4000h For the following statements, state whether or not the instruction is valid. Give comment to describe the reason why the instruction become valid or invalid. mov ax, MyByte mov ax,MyWord What will be the value of the destination operand after each of the following instructions executes in sequence? mov ax, MyWord ; c) ax:______________________________ mov ax,[MyWord + 2] ; d) ax:_____________________________ add ax, [MyWord + 2] ; e) ax:_____________________________

By Using PTR keywords, create and complete the following program that can produce the following output based on given variables.    .data varB BYTE 65h,31h,56h,65h varW WORD 6543h,1202h varD DWORD 87654321h .code mov _____________________ ; answer : 6556h mov _____________________ ; answer : 21h mov _____________________ ; answer : 02h mov _____________________ ; answer: 8765 mov _____________________ ; answer : 12026543h

mov ax,WORD PTR [varB+2] mov bl,BYTE PTR varD mov bl,BYTE PTR [varW+2] mov ax,WORD PTR [varD+2] mov eax,DWORD PTR varW

TITLE Add and Subtract, Version 2 (AddSub2. asm) INCLUDE Irvine32. inc TITLE Add and Subtract, Version 2 (AddSub2.asm) INCLUDE Irvine32.inc .data val1 dword 10000h val2 dword 40000h val3 dword 0DDh val4 dword 200h finalVal dword ? .code main PROC add eax,val1 ; start with 10000h add eax,val2 ; add 40000h sub eax,val3 ; subtract 20000h add eax,val4 mov finalVal,eax ; store the result (30000h) Call DumpRegs ; display the registers Exit main ENDP END main

TITLE mul binary and hexa, Version 2 (mulbinhexa.asm) INCLUDE Irvine32.inc .data num1 dword 1111b num2 dword 0Ah finalnum dword ? .code main PROC mov eax,num1 ; start 100b mov eax,num2 ; mul 11b mul eax mov finalnum,eax ; store the result (12=C call DumpRegs ; display the registers exit main ENDP END main