Difference between revisions of "CSC231 Flags Settings Examples"
Line 1: | Line 1: | ||
− | < | + | --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 20:54, 3 November 2014 (EST) |
+ | ---- | ||
+ | |||
+ | <br /> | ||
+ | <source lang="java"> | ||
;;; ------------------------------------------------------------------- | ;;; ------------------------------------------------------------------- | ||
;;; flagbits.asm | ;;; flagbits.asm | ||
Line 60: | Line 64: | ||
int 0x80 ; final system call | int 0x80 ; final system call | ||
− | </ | + | </source> |
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC231]][[Category:Nasm]] |
Revision as of 20:54, 3 November 2014
--D. Thiebaut (talk) 20:54, 3 November 2014 (EST)
;;; -------------------------------------------------------------------
;;; flagbits.asm
;;; D. Thiebaut
;;;
;;; a program with several compare instructions and the resulting
;;; flags generated by the ALU.
;;; This program was debugged by ddd and the flags resulting from
;;; the execution of each instruction was then added as a comment
;;; on the same line as the instruction.
;;; The flags are
;;; CF: carry
;;; PF: parity (1 if the number of 1s in the result is even)
;;; AF: auxiliary carry (carry into the MSB)
;;; SF: sign (1 if result is negative, 0 otherwise)
;;; ZF: zero (1 if result is 0, 1 otherwise)
;;; IF: interrupt flag (used for critical sections)
;;; OF: overflow (1 if the result overflowed assuming signed numbers)
;;; ID: direction bit (for string operations)
;;; -------------------------------------------------------------------
EXIT equ 1
;; ------------------------------------------------------------
;; data areas
;; ------------------------------------------------------------
section .data
;; ------------------------------------------------------------
;; code area
;; ------------------------------------------------------------
section .text
global _start
_start: nop
nop ; immediate Flag values
; value AFTER the instruction
;----------- ----------------------
mov al, 0x43 ; 67
cmp al, 0x43 ; PF ZF IF ID
cmp al, 0x42 ; 66 IF ID
cmp al, 0x44 ; 68 CF PF AF SF IF ID
cmp al, 0xff ; 255 or -1 CF PF AF IF ID
cmp al, 0x81 ; 129 or -127 CF SF IF OF ID
mov al, 0xfe ; 254, or -2
cmp al, 0xff ; 255 or -1 CF PF AF SF IF ID
cmp al, 0xfd ; 253 or -3 IF ID
cmp al, 0x81 ; 129 or -127 PF IF ID
cmp al, 0x7f ; 127 AF IF OF ID
;; exit()
mov eax,EXIT
mov ebx,0
int 0x80 ; final system call