Difference between revisions of "CSC231 Flags Settings Examples"

From dftwiki3
Jump to: navigation, search
(Same Code, With Subs instead of Cmps)
 
(2 intermediate revisions by the same user not shown)
Line 66: Line 66:
 
</source>
 
</source>
 
<br />
 
<br />
 +
==Same Code, With Subs instead of Cmps==
 +
<br />
 +
<br />
 +
<source lang="java">
 +
;;; -------------------------------------------------------------------
 +
;;; 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
 +
 +
</source>
 
<br />
 
<br />
 
<br />
 
<br />

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