Computer Organization & Assembly Language Lecture PDF

Summary

This lecture presents an introduction to computer organization and assembly language. Key concepts are explored, including the use of libraries like Irvine32 and Kernel32. The lecture also touches upon important procedures and descriptions relating to programming.

Full Transcript

Computer Organization & Assembly Language INSTRUCTOR NAME: ENGR. UMAIR HAFEEZ KHAN BS (CS), 3 R D SEMESTER, AIOU Topics for today 1. Linking to a library 2. Irvine32 library 3. Different Functions in Irvine32 What is a link library (in context of programming) A link library consists of procedure...

Computer Organization & Assembly Language INSTRUCTOR NAME: ENGR. UMAIR HAFEEZ KHAN BS (CS), 3 R D SEMESTER, AIOU Topics for today 1. Linking to a library 2. Irvine32 library 3. Different Functions in Irvine32 What is a link library (in context of programming) A link library consists of procedures that have been previously implemented, assembled into machine code A link library begins as one or more source code files, which are assembled into object files The object files are inserted into link library files In order to save time, the previously implemented functions can be compiled into a single file ready for later use. The source code has to be linked to a library file in order to successfully call functions from the library file Developing libraries in assembly language requires advanced programming skills Some libraries are already available for system input-output functions How to add library to solution in visual studio 1. Right click console application 2. Find the downloaded library irvine32.lib 3. Click add 4. Later on, simply use INCLUDE Download irvine 32 library Irvine32 & Kernel32.lib Irvine32 library provides complex input-output functions with simpler interfaces Irvine32 can be used in programs running in 32-bit mode. Contains procedures that link to the MS-Windows API (Application Programming Interface) when they generate input-output kernel32.lib, part of the Microsoft Windows Platform Software Development kit, contains linking information for system functions located in a file named kernel32.dll Kernel32.dll is a fundamental part of MS-windows, and is called dynamic link library Kernel32.dll contains executable functions that perform character-based input-output. Irvine32 & Kernel32.lib Procedures found in Irvine32 CloseFile GetDateTime OpenInputFile ReadHex CLrscr GetMaxXY ParseDecimal32 ReadInt CreateOutputFile GetMseconds ParseInteger32 ReadKey Crlf GetTextColor Random32 ReadString Delay GotoXY Randomize SetTextColor DumpMem IsDigit RandomRange Str_Compare DumpRegs MsgBox ReadChar Str_copy GetCommandTail MsgBoxAsk ReadFromFile Str_length Str_trim WriteBin WriteDec WriteInt WriteString Str_ucase WriteBinB WriteHex WriteStackFram WriteToFile e WaitMsg WriteChar WriteHexB WriteStackFram WriteWindowMs eName g Procedure Descriptions CloseFile: Closes the file that was previously created or opened Clrscr: Clears console window CreateOutputFile: Creates a new file and opens it for writing, uses Edx for offset of filename Crlf : Advances cursor to the beginning of the next line Delay: Pauses the program for a specified number of milliseconds, before calling Delay, set EAX to the desired interval DumpMem: Writes a range of memory to the console window in hexadecimal, starting address of memory is passed to ESI, the number of units in ECX, and the unit size in EBX (1= byte, 2 = word, 4 = doubleword) Procedure Descriptions DumpRegs: Displays the EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP and EFL registers in hexadecimal. Also displays values of carry, sign, Zero, Overflow, Auxiliary Carry and Parity Flags. GetCommandTail: accepts parameters on the command line provided by the user Command line parameters in visual studio Procedure Descriptions GetMaxXY: Gets the Size of console window’s buffer, if the console window buffer is larger than the visible window size, scroll bars appear automatically. GetMaxXY has no input paramters, when it returns, the DX register contains the number of buffer columns and AX contains the number of buffer rows. The possible range of each value is less or equal to 255 MsgBox: Displays a graphical popup message box with an optional caption. The string saved in EDX will appear inside the box. Pass the box title in EBX, to leave title blank, set Ebx to zero MsgBoxAsk: Displays graphical pop up message with Yes and No buttons (works when the program is running in console window). Pass the offset of a string for the box’s title in EBX. MsgBoxAsk returns an integer in EAX that tells you which button was selected by the user IDYES returns 6, IDNO returns 7 Procedure Descriptions OpenInputFile: Opens an existing file for input. Pass it offset of a filename in Edx. When it returns, if the file is opened successfully, EAX will contain a valid file handle. Otherwise EAX will equal INVALID_FILE _VALUE (a predefined constant) Conditional Processing Conditional Processing gives the program the ability to make decisions. Bases on Boolean operations that are core of all decision statements because they affect the CPU status flags. Later, jump and loop instructions that interpret CPU status flags are shown the most fundamental structures in theoretical computer science, the Finite- state Machine is implemented using conditional processing Conditional Branching A technique known as Conditional branching lets the programmer alter the flow of control All the IF, SWITCH, Conditional Loop found in high level languages has built- in branching logic. Programs that deal with hardware devices must be able to manipulate individual bits in numbers Individual bits must be tested, cleared and set. Boolean and Comparison Instructions The intel instruction set contains the AND, OR, XOR and NOT instructions, which directly Implement operations in binary bits Another instruction is TEST instruction, checks whether a particular bit is set or cleared CPU status Flags Boolean instructions affect the zero, carry, sign, overflow and parity flags 1. The Zero flag is set when the result of an operation equals zero 2. The carry flag is set when the operation generates a carry out of the highest bit of the destination operand 3. The sign flag is a copy of the high bit of the destination operand, indicating that it is negative if set, positive if clear) 4. Overflow flag is set when an instruction generates a result that is outside the signed range of the destination operand 5. The parity flag is set when an instruction generates an even number of 1 bits in the low byte of the destination operand AND instruction The following operand combinations are permitted for AND instruction, immediate operand can be no longer than 32 bits AND reg,reg AND reg,mem AND reg,imm AND mem,reg AND mem,imm The other operands can be 8, 16, 32, or 64 bits and they must be the same size AND Instruction AND instruction lets the programmer clear 1 or more bits in an operand without affecting other bits. This technique is called bit masking. and AL,11110110b ; clear bits 0 and 3, leave others unchanged mov al,10101110b and al,11110110b ; result in AL = 10100110 Flags affected by AND instruction AND instruction always clears the overflow and carry flags. It modifies the sign, zero, parity flags in a way that is consistent with the value assigned to the destination operand. If the following manipulation results in a zero value in the EAX register, in that case, the zero flag will be set and EAX, 1Fh Converting Characters to upper case.data array BYTE 50 DUP(?).code mov ecx,LENGTHOF array mov esi,OFFSET array L1: and BYTE PTR [esi],11011111b ; clear bit 5 inc esi loop L1 THE END

Use Quizgecko on...
Browser
Browser