Download presentation
Presentation is loading. Please wait.
Published byTamsin Lester Modified over 9 years ago
1
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003
2
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 2 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs
3
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 3 Flag Register The flag register stores the condition flags that retain useful information of the past computation, especially as a consequence of the previous arithmetic operation. The following flags are noteworthy: –OOverflow –SSign –ZZero –PParity (=1 if the number of 1’s in the result is odd) –CCarry (= carry-out from most significant bit) –IInterrupt (= 1 means interrupts are enabled; important in I/O programming, a future topic) Flags are necessary to implement conditional jumps. Recall the following from computer arithmetic: –1000 + 1100 = 0100O = 1; Z = 0; S = 0; P = 1; C = 1
4
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 4 Flags A flag is a bit (0 or 1) in the flags register, a 16-bit register in the CPU. There are nine flags: three control flags and six status flags. The remaining seven bits of the flags register are unused. The three control flags are set (set means changes to 1) or reset (also called cleared, which means changes to 0) by instructions in the program. 15 14 13 1211 10 9 8 7 6 5 4 3 2 1 0 - - - - O D I T S Z - A - P - C Bit position 16-bit register Flags
5
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 5 Category Bit # FlagNameDescription Control 10 9 8 DITDIT Direction Interrupt Trap 1 : blocks in memory copied from high address to low. 0 : blocks in memory copied from low address to high. 1 : hardware interrupts are allowed. 0 : hardware interrupts are not allowed. 1 : program halts after each instruction. 0 : program dos not halts after each instruction. Status 0 11 7 6 4 2 COSZAPCOSZAP Carry Overflow Sign Zero Auxiliary carry Parity 1 : when result of an unsigned arithmetic operation is too large. 1 : when result of a signed arithmetic operation is too large. 1 : when result of an arithmetic or logical operation is negative. 1 : when result of an arithmetic or logical operation is zero. 1 : when result of an operation causes a carry from bit 3 to bit 4. 1 : when result of an operation contains even number of 1-bits.
6
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 6 Compare Instruction dest-source UnsignedSigned CZZS,O <0 (dest<source)10?!= =0 (dest=source)011? >0 (dest>source)000=
7
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 7 Mnemonics We will learn only a subset of the opcodes available. If you are interested, you could read about the rest. Usually, in a current generation machine, the size of the instruction set can grow to several hundred instructions. [What is the advantage of a large instruction set? Disadvantage?]
8
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 8 MnemonicsMeaning add addition of two integers sub subtraction between two integers mul multiply two integers div divide one integer by another mov copy from source to destination inc increment operand by 1 dec decrement operand by 1 cmp compare two operands by sub and and of two operands or or of two operands xor xor of two operands ror or rol rotate shift right or left shr or shl logical shift right or left jmp jump to a different instruction loop repeat loop with cx as counter MnemonicsMeaning je jump if equal jz jump if zero jg jump if greater than jge jump if greater than or equal jl jump if less than jle jump if less than or equal jne jump if not equal jo jump if overflow push push operand onto stack pop pop operand from stack call jump to subroutine ret return from subroutine Few Mnemonics
9
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 9 Basic I/O We will make our lives easier by using some I/O functions supported by the OS. These I/O functions are software traps (interrupts) whose invocation causes a transfer of control to the corresponding OS (software) interrupt handler. These handlers can be considered as special subroutines that will be invoked whenever the int (software interrupt) instruction is executed. In Linux, int 0x80 the specific interrupt that we will use. (In DOS, it is int 21h). Parameters are passed from our program through registers from your program to the OS subroutine with a well-defined interface specification.
10
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 10 Output EAX = 4; 4 is a system call for Output EBX = 1; the device, screen, or STDOUT ECX = addr; starting address of the stuff to output; like a pointer to a buffer; char* EDX = length of the buffer Example: hello.asm
11
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 11 Input EAX = 3; EBX = 0; Standard input or keyboard; STDIN ECX = addr; address of the destination buffer EDX = max # of bytes to enter After int, EDX will have the length of the data actually read in bytes
12
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 12 Program Termination EAX = 1 EBX = exit code; EBX = 0 means successful termination to the calling program.
13
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 13 System Call Interface A topic of the System Software and OS courses. The goal is to abstract programmer from knowing hardware details when doing I/O. Input is similar to read() system call in C Output to write() Termination to exit() Whenever a system call is executed, it traps to kernel to carry out the requested operation on behalf of the user program using appropriate device driver.
14
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 14 Exercises Give an instruction that involves moving the content of some memory location to another memory location. –mov al, [mem_loc1] –mov [mem_loc2], al
15
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 15 Exercises (2) Write a program that moves 100 bytes from memory location input_buf to memory location output_buf. See movbytes.asm
16
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 16 Exercises (3) Give a assembly language ‘instruction’ that does not correspond to a machine language instruction. –mov [output_buf], [input_buf]
17
October 1, 2003Serguei A. Mokhov, mokhov@cs.concordia.ca 17 Exercises (4) Write a program that accepts 25 characters from the keyboard and buffer them in memory location input_buf. Afterwards, the characters are printed. See printchars.asm.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.