Difference between revisions of "CSC231 Flags Settings Examples"
(→Same Code, With Subs instead of Cmps) |
|||
(One intermediate revision by the same user not shown) | |||
Line 113: | Line 113: | ||
mov al, 0x43 ; 67 | mov al, 0x43 ; 67 | ||
sub al, 0x43 ; PF ZF IF ID | sub al, 0x43 ; PF ZF IF ID | ||
+ | |||
+ | mov al, 0x43 ; 67 | ||
sub al, 0x42 ; 66 IF ID | sub al, 0x42 ; 66 IF ID | ||
+ | |||
+ | mov al, 0x43 ; 67 | ||
sub al, 0x44 ; 68 CF PF AF SF IF ID | sub al, 0x44 ; 68 CF PF AF SF IF ID | ||
+ | |||
+ | mov al, 0x43 ; 67 | ||
sub al, 0xff ; 255 or -1 CF PF AF IF ID | sub al, 0xff ; 255 or -1 CF PF AF IF ID | ||
+ | |||
+ | mov al, 0x43 ; 67 | ||
sub al, 0x81 ; 129 or -127 CF SF IF OF ID | sub al, 0x81 ; 129 or -127 CF SF IF OF ID | ||
mov al, 0xfe ; 254, or -2 | mov al, 0xfe ; 254, or -2 | ||
sub al, 0xff ; 255 or -1 CF PF AF SF IF ID | sub al, 0xff ; 255 or -1 CF PF AF SF IF ID | ||
+ | mov al, 0xfe ; 254, or -2 | ||
sub al, 0xfd ; 253 or -3 IF ID | sub al, 0xfd ; 253 or -3 IF ID | ||
+ | mov al, 0xfe ; 254, or -2 | ||
sub al, 0x81 ; 129 or -127 PF IF ID | sub al, 0x81 ; 129 or -127 PF IF ID | ||
+ | mov al, 0xfe ; 254, or -2 | ||
sub al, 0x7f ; 127 AF IF OF ID | sub al, 0x7f ; 127 AF IF OF ID | ||
Latest revision as of 06:42, 29 March 2017
--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
Same Code, With Subs instead of Cmps
;;; -------------------------------------------------------------------
;;; 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
sub al, 0x43 ; PF ZF IF ID
mov al, 0x43 ; 67
sub al, 0x42 ; 66 IF ID
mov al, 0x43 ; 67
sub al, 0x44 ; 68 CF PF AF SF IF ID
mov al, 0x43 ; 67
sub al, 0xff ; 255 or -1 CF PF AF IF ID
mov al, 0x43 ; 67
sub al, 0x81 ; 129 or -127 CF SF IF OF ID
mov al, 0xfe ; 254, or -2
sub al, 0xff ; 255 or -1 CF PF AF SF IF ID
mov al, 0xfe ; 254, or -2
sub al, 0xfd ; 253 or -3 IF ID
mov al, 0xfe ; 254, or -2
sub al, 0x81 ; 129 or -127 PF IF ID
mov al, 0xfe ; 254, or -2
sub al, 0x7f ; 127 AF IF OF ID
;; exit()
mov eax,EXIT
mov ebx,0
int 0x80 ; final system call