CS2422 Assembly Language & System Programming November 21, 2006.

Slides:



Advertisements
Similar presentations
Introduction – This book introduces to the design and implementation of System Software
Advertisements

Chapter Outline Chapter 1 of Beck’s “System Software” book
System Programming Design and Implementation of system software.
Computing Machinery Chapter 7: Register Transfers.
系 統 程 式 System Programming
System Programming Mid-Term Date: October 28th, 2005 Time: 09:10-12:00.
Welcome to Systems Software The purpose of this course is to provide background in fundamental types of system software, particularly assemblers, loaders,
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
The Simplified Instructional Computer (SIC/SICXE)
1: Background1 System Programming ( 系統程式 ) Main goal: r What is a system software? m Compiler m Assembler m Loader and Linker m Debugger… r To design and.
Simplified Instructional Computer (SIC). SIC Architecture Two versions: SIC and SIC/XE (extra equipments). SIC program can be executed on SIC/XE. Memory.
SP Mid-Term Exam Chang-Yu Wu 2006/12/03. Q1. Consider the memory contents shown in the following figure. What would be loaded to register A with the instruction.
SYSTEM SOFTWARE Dr.A.KANNAN, PROFESSOR & HEAD, DEPARTMENT OF IST CS2304.
System Software by Leland L. Beck chapter 1, pp.1-20.
Chapter 1 Background System Software Chih-Shun Hsu
1 Chapter 1 Background Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
1 The Simplified Instructional Computer (SIC) Hsiang-Fu Yu National Taipei University of Education.
System Programming System Software:
System Software.
System Software by Leland L. Beck chapter 1, pp.1-20.
Assembler design.
Chapter 6: Machine dependent Assembler Features
System Programming Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
An introduction to systems programming
System Programming System Software:
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Assembler (Basic Functions)
Computer Architecture
MIPS Instruction Set Advantages
Background. Outlines Brief introduction to system software System software and machine architecture Simplified Instructional Computer (SIC) –Architecture.
Topics Introduction Hardware and Software How Computers Store Data
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Microcode Source: Digital Computer Electronics (Malvino and Brown)
Execution of an instruction
1 Assemblers System Programming by Leland L. Beck Chapter 2.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
1/23/20067CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background III.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Operating Systems A Biswas, Dept. of Information Technology.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
Machine dependent Assembler Features
Addressing Modes in Microprocessors
MIPS Instruction Set Advantages
Prof . Ki-Dong Chung Pusan Nat’l University
System Programming and administration
System Programming and administration
System Programming Design and Implementation of system software.
SYSTEM SOFTWARE - UNIT II
THE sic mACHINE CSCI/CMPE 3334 David Egle.
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Instructions - Type and Format
CSCE Fall 2013 Prof. Jennifer L. Welch.
Simplified Instructional Computer (SIC)
Chapter 1 Background Professor Gwan-Hwan Hwang
Simplified Instructional Computer (SIC)
ultraSPARC과 SIC/XE Machine 비교
CSCE Fall 2012 Prof. Jennifer L. Welch.
Assemblers CSCI/CMPE 3334 David Egle.
Welcome to Systems Software
Chapter 6 Programming the basic computer
SYSTEM SOFTWARE CS2304 Dr.A.KANNAN, PROFESSOR & HEAD,
An introduction to systems programming
Lecture 1: SIC Architecture
Presentation transcript:

CS2422 Assembly Language & System Programming November 21, 2006

Today’s Topics (1/2) Assignment 3 –Windows (graphics mode) programming. –Linking to an assembly procedure. –Setting up Visual C Express.

References Setting up Platform SDK: see the course webpage. Setting up Visual C to compile and link assembly code with C or C++ code: included in the download file theForger’s Win32 API Tutorial (Read at least the first two articles.)

Demo The program creates a “mosaic” effect on your windows desktop. You need to set your display to use 24-bit or 32-bit colors. Using ML.exe /Zi option to enable debugging directly within your assembly code at Visual C++. (Already done for you if you use VC Express.)

Assembly Code to Be Written Mosaic(img, resX, resY, x, y, blockX, blockY)

Example Code Mosaic_C_version() in main.c shows the algorithm. To run the assembly code, remember to comment out: #define MOSAIC_C_VERSION The Mosaic procedure in mosaic.asm gives an example of accessing parameters and local variables.

Img: a 2D Array The img[] is conceptually 2D, but stored as if it is a 1D array. A pixel at location (x, y) is stored at img[x + y * xRes] Each pixel stores the Red, Green, Blue components of a color in 4 bytes: struct { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD;

Basic Structure of a Windows Program WinMain procedure. WinProc procedure. Section 11.2 explains the above in assembly. The C version in main.c might be easier to read. An excellent introductory material can be found at: (Read at least the first two articles.)

WinMain Procedure Every Windows application needs a startup procedure, usually named WinMain, which is responsible for the following tasks: Get a handle to the current program Load the program’s icon and mouse cursor Register the program’s main window class and identify the procedure that will process event messages for the window Create the main window Show and update the main window Begin a loop that receives and dispatches messages

WinProc Procedure WinProc receives and processes all event messages relating to a window –Some events are initiated by clicking and dragging the mouse, pressing keyboard keys, and so on WinProc decodes each message, carries out application-oriented tasks related to the message WinProc PROC, hWnd:DWORD,; handle to the window localMsg:DWORD, ; message ID wParam:DWORD, ; parameter 1 (varies) lParam:DWORD; parameter 2 (varies) (Contents of wParam and lParam vary, depending on the message.)

What Will You Learn from This Assignment? Linking C and Assembly. The first step in Windows programming. Array processing. Implementation of nontrivial loops.

Today’s Topic (2/2) Chapter 1 of Beck’s “System Software” book.

Study Guide 1.1 Introduction 1.2 System Software and Machine Architecture 1.3 The Simplified Instructional Computer (SIC) –SIC Machine Architecture –SIC/XE Machine Architecture –SIC Programming Examples

Introduction Definition of System software –System software consists of a variety of programs that support the operation of a computer E.g. of system software –Text editor, compiler, loader or linker, debugger, macro processors, operating system, database management systems, software engineering tools, ….

System Software and Machine Architecture (1/2) One characteristic in which most system software differs from application software is machine dependency System programs are intended to support the operation and use of the computer itself, rather than any particular application.

System Software and Machine Architecture (2/2) Because most system software is machine- dependent, we must include real machines and real pieces of software in our study. Simplified Instructional Computer (SIC) –SIC is a hypothetical computer that has been carefully designed to include the hardware features most often found on real machines, while avoiding unusual or irrelevant complexities

The Simplified Instructional Computer (SIC) Like many other products, SIC comes in two versions –The standard model –An XE version “extra equipments”, “extra expensive” The two versions has been designed to be upward compatible

SIC Machine Architecture (1/7) Memory –Memory consists of 8-bit bytes –Any 3 consecutive bytes form a word (24 bits) –Total of (2 15 ) bytes in the computer memory

SIC Machine Architecture (2/7) Registers –Five registers –Each register is 24 bits in length MnemonicNumberSpecial use A0 Accumulator X1 Index register L2 Linkage register PC8 Program counter SW9 Status word

SIC Machine Architecture (3/7) Data Formats –Integers are stored as 24-bit binary number –2’s complement representation for negative values –Characters are stored using 8-bit ASCII codes –No floating-point hardware on the standard version of SIC

SIC Machine Architecture (4/7) Instruction Formats –Standard version of SIC 8115 opcodexaddress The flag bit x is used to indicate indexed-addressing mode

SIC Machine Architecture (5/7) Addressing Modes –There are two addressing modes available Indicated by x bit in the instruction ModeIndicationTarget address calculation Directx=0TA=address Indexedx=1TA=address+(X) (X): the contents of register X

SIC Machine Architecture (6/7) Instruction Set –Load and store registers LDA, LDX, STA, STX, etc. –Integer arithmetic operations ADD, SUB, MUL, DIV All arithmetic operations involve register A and a word in memory, with the result being left in A –COMP –Conditional jump instructions JLT, JEQ, JGT –Subroutine linkage JSUB, RSUB –See appendix A, Page 495

SIC Machine Architecture (7/7) Input and Output –Input and output are performed by transferring 1 byte at a time to or from the rightmost 8 bits of register A Test Device TD instruction Read Data (RD) Write Data (WD)

SIC Programming Examples (Fig 1.2a) LDAFIVE STAALPHA LDCHCHARZ STCHC1. ALPHARESW1one-word variable FIVEWORD5one-word constant CHARZBYTEC’Z’one-byte constant C1RESB1one-byte variable

SIC Programming Example (Fig 1.3a) LDAALPHA ADD INCR SUBONE STABETA LDAGAMMA ADDINCR SUBONE STADELTA... ONEWORD1one-word constant ALPHARESW1one-word variables BETARESW1 GAMMARESW1 DELTARESW1 INCRRESW1

SIC Programming Example (Fig 1.4a) LDXZERO initialize index register to 0 MOVECHLDCHSTR1,X load char from STR1 to reg A STCHSTR2,X TIXELEVEN add 1 to index, compare to 11 JLTMOVECH loop if “less than”. STR1BYTEC’TEST STRING’ STR2RESB11 ZEROWORD0 ELEVENWORD11

SIC Programming Example (Fig 1.5a) LDAZERO initialize index value to 0 STAINDEX ADDLPLDXINDEX load index value to reg X LDAALPHA,X load word from ALPHA into reg A ADDBETA,X STAGAMMA,X store the result in a word in GAMMA LDAINDEX ADDTHREE add 3 to index value STAINDEX COMPK300 compare new index value to 300 JLTADDLP loop if less than INDEXRESW1 ALPHARESW100 array variables—100 words each BETARESW100 GAMMARESW100 ZEROWORD0 one-word constants THREEWORD3 K300WORD300

SIC Programming Example (Fig 1.6) INLOOPTDINDEV test input device JEQINLOOP loop until device is ready RDINDEV read one byte into register A STCHDATA. OUTLPTDOUTDEV test output device JEQOUTLP loop until device is ready LDCHDATA WDOUTDEV write one byte to output device. INDEVBYTEX’F1’ input device number OUTDEVBYTEX’05’ output device number DATARESB1

SIC/XE Machine Architecture (1/13) Memory –Maximum memory available on a SIC/XE system is 1 megabyte (2 20 bytes)

SIC/XE Machine Architecture (2/13) Registers –Additional registers are provided by SIC/XE MnemonicNumberSpecial use B3 Base register S4 General working register T5 F6 Floating-point accumulator (48 bits)

SIC/XE Machine Architecture (3/13) There is a 48-bit floating-point data type sexponentfraction F*2 (e-1024)

SIC/XE Machine Architecture (4/13) Instruction Formats 8 op 844 r1r2 Format 1 (1 byte) Format 2 (2 bytes) Formats 1 and 2 are instructions that do not reference memory at all opnixbpedisp Format 3 (3 bytes) opnixbpeaddress Format 4 (4 bytes)

SIC/XE Machine Architecture (5/13) Addressing modes –Base relative (n=1, i=1, b=1, p=0) –Program-counter relative (n=1, i=1, b=0, p=1) –Direct (n=1, i=1, b=0, p=0) –Immediate (n=0, i=1, x=0) –Indirect (n=1, i=0, x=0) –Indexing (both n & i = 0 or 1, x=1) –Extended (e=1)

SIC/XE Machine Architecture (6/13) Base Relative Addressing Mode nixbpe opcode1110disp n=1, i=1, b=1, p=0, TA=(B)+disp (0  disp  4095) Program-Counter Relative Addressing Mode nixbpe opcode1101disp n=1, i=1, b=0, p=1, TA=(PC)+disp (-2048  disp  2047)

SIC/XE Machine Architecture (7/13) Direct Addressing Mode nixbpe opcode1100disp n=1, i=1, b=0, p=0, TA=disp (0  disp  4095) nixbpe opcode11100disp n=1, i=1, b=0, p=0, TA=(X)+disp (with index addressing mode)

SIC/XE Machine Architecture (8/13) Immediate Addressing Mode nixbpe opcode010disp n=0, i=1, x=0, operand=disp Indirect Addressing Mode nixbpe opcode100disp n=1, i=0, x=0, TA=(disp)

SIC/XE Machine Architecture (9/13) Simple Addressing Mode nixbpe opcode00disp i=0, n=0, TA=bpe+disp (SIC standard) nixbpe opcode11disp i=1, n=1, TA=disp (SIC/XE standard)

SIC/XE Machine Architecture (10/13) Addressing Modes Summary (p.499)

SIC/XE Machine Architecture (11/13) Instruction Format

SIC/XE Machine Architecture (12/13) Instruction Set –Instructions to load and store the new registers LDB, STB, etc. –Floating-point arithmetic operations ADDF, SUBF, MULF, DIVF –Register move instruction RMO –Register-to-register arithmetic operations ADDR, SUBR, MULR, DIVR –Supervisor call instruction SVC

SIC/XE Machine Architecture (13/13) Input and Output –There are I/O channels that can be used to perform input and output while the CPU is executing other instructions

SIC/XE Programming Examples (Fig 1.2b) LDA#5 STAALPHA LDCH#90 STCHC1. ALPHARESW1 C1RESB1 LDAFIVE STAALPHA LDCHCHARZ STCHC1. ALPHARESW1 FIVEWORD5 CHARZBYTEC’Z’ C1RESB1 SIC version SIC/XE version

SIC/XE Programming Example (Fig 1.3b) LDSINCR LDAALPHA ADDR S,A SUB#1 STABETA LDAGAMMA ADDRS,A SUB#1 STADELTA... ALPHARESW1one-word variables BETARESW1 GAMMARESW1 DELTARESW1 INCRRESW1

SIC/XE Programming Example (Fig 1.4b) LDT#11 initialize register T to 11 LDX#0 initialize index register to 0 MOVECHLDCHSTR1,X load char from STR1 to reg A STCHSTR2,X store char into STR2 TIXRT add 1 to index, compare to 11 JLTMOVECH loop if “less than” 11. STR1BYTEC’TEST STRING’ STR2RESB11

SIC/XE Programming Example (Fig 1.5b) LDS#3 LDT#300 LDX#0 ADDLPLDAALPHA,X load from ALPHA to reg A ADDBETA,X STAGAMMA,X store in a word in GAMMA ADDRS,X add 3 to index value COMPRX,T compare to 300 JLTADDLP loop if less than ALPHARESW100 array variables—100 words each BETARESW100 GAMMARESW100

SIC/XE Programming Example (Fig 1.7b)