![Page 1: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/1.jpg)
Introduction to 8086 Assembly Lecture 4
Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size
![Page 2: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/2.jpg)
Decimal numbers
https://learn.mikroe.com/ebooks/picmicrocontrollersprogramminginassembly/front-matter/introduction-to-the-world-of-microcontrollers/
![Page 3: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/3.jpg)
Binary numbers
https://learn.mikroe.com/ebooks/picmicrocontrollersprogramminginassembly/front-matter/introduction-to-the-world-of-microcontrollers/
mov al, 218mov al, 11011010b
![Page 4: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/4.jpg)
Decimal to binary conversion
http://www.math-only-math.com/conversion-of-numbers.html
mov eax, 4215mov eax, 1000001110111b
![Page 5: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/5.jpg)
Hexadecimal numbers (hex)
mov ax, 0A9E2hmov ax, 0xA9E2
Binary Hex Decimal0000 0 00001 1 10010 2 20011 3 30100 4 40101 5 50110 6 60111 7 71000 8 81001 9 91010 A 101011 B 111100 C 121101 D 131110 E 141111 F 15
![Page 6: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/6.jpg)
Convert hex to/from binary
https://learn.mikroe.com/ebooks/picmicrocontrollersprogramminginassembly/front-matter/introduction-to-the-world-of-microcontrollers/
https://codegolf.stackexchange.com/questions/53001/hexadecimal-counter
![Page 7: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/7.jpg)
Signed integers
● Sign bit○ 12 = 11002 0 0 0 0 1 1 0 0
sign bit
![Page 8: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/8.jpg)
Signed integers
● Sign bit○ 12 = 11002 ○ -12
1 0 0 0 1 1 0 0
sign bit
0 0 0 0 1 1 0 0
![Page 9: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/9.jpg)
Signed integers
● Sign bit○ +0○ -0
1 0 0 0 0 0 0 0
sign bit
0 0 0 0 0 0 0 0
![Page 10: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/10.jpg)
One's complement
● Sign bit○ 12 = 11002 ○ -12
mov al, 12not al
1 1 1 1 0 0 1 1
0 0 0 0 1 1 0 0
0 0 0 0 1 1 0 0
1 1 1 1 0 0 1 1
AL
AL
![Page 11: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/11.jpg)
One's complement
● Representing 0○ +0○ -0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
![Page 12: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/12.jpg)
two's complement
binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254255 11111111 FF 255
8 bits
mov al, 255add al, 1
al=?
11111111+ 1
![Page 13: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/13.jpg)
two's complement
binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254255 11111111 FF 255
8 bits
mov al, 255add al, 1
al=0
11111111+ 1
![Page 14: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/14.jpg)
two's complement
binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254255 11111111 FF 255
8 bits
mov al, 255add al, 3
al=?
11111111+ 11
![Page 15: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/15.jpg)
two's complement
binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254255 11111111 FF 255
8 bits
mov al, 255add al, 3
al=2
11111111+ 11
![Page 16: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/16.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254-1 11111111 FF 255
8 bits
mov al, 255add al, 1al=0
mov al, 255add al, 3al=2
![Page 17: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/17.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253254 11111110 FE 254-1 11111111 FF 255
8 bits
mov al, 254add al, 2al=0
![Page 18: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/18.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
253 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
mov al, 254add al, 2al=0
![Page 19: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/19.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129130 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 20: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/20.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 21: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/21.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128129 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
where to put the boundary?
![Page 22: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/22.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
where to put the boundary?
![Page 23: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/23.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
where to put the boundary?
![Page 24: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/24.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126-129 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
where to put the boundary?
![Page 25: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/25.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125-130 01111110 7E 126-129 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
where to put the boundary?
![Page 26: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/26.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
What is special about -128 ≡ 1000000?
![Page 27: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/27.jpg)
two's complement
● mov AL, 0xFF○ How do we know if AL stores a signed integer or an unsigned integer?○ How do we know if AL=-1 or AL=255?
![Page 28: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/28.jpg)
two's complement
● mov AL, 0xFF○ How do we know if AL stores a signed integer or an unsigned integer?○ How do we know if AL=-1 or AL=255?○ How do we know if AL stores
■ A signed integer with signed bit?■ A 1's complement signed integer?■ A 2's complement signed integer?■ An unsigned integer?■ the ASCII code of a character?
![Page 29: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/29.jpg)
two's complement
● add AL, BL○ signed or unsigned addition?
● sub EDI, ESI○ signed or unsigned subtraction?
![Page 30: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/30.jpg)
two's complement
● add AL, BL○ signed or unsigned addition?
● sub EDI, ESI○ signed or unsigned subtraction?
● Does not matter when 2's complement signed integers are used
![Page 31: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/31.jpg)
two's complement
● add AL, BL○ signed or unsigned addition?
● sub EDI, ESI○ signed or unsigned subtraction?
● Does not matter when 2's complement signed integers are used● Not the case for multiplication and division
![Page 32: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/32.jpg)
two's complement
● 8 bits: -128 to 127 (-27 to 27-1)● 16 bits: -215 to 215-1● 32 bits: -231 to 231-1● n bits: -2n-1 to 2n-1-1
![Page 33: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/33.jpg)
two's complement
● 8 bits: -128 to 127 (-27 to 27-1)● 16 bits: -215 to 215-1● 32 bits: -231 to 231-1● n bits: -2n-1 to 2n-1-1
● mov eax, 0xFFFFFFFF● eax=?
○ signed 2's complement○ unsigned
![Page 34: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/34.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 35: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/35.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 36: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/36.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 37: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/37.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
![Page 38: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/38.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
not alinc al
![Page 39: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/39.jpg)
two's complement
signed binary hex unsigned0 00000000 00 01 00000001 01 12 00000010 02 2
: : : :
125 01111101 7D 125126 01111110 7E 126127 01111111 7F 127-128 10000000 80 128-127 10000001 81 129-126 10000010 82 130
: : : :
-3 11111101 FD 253-2 11111110 FE 254-1 11111111 FF 255
8 bits
not alinc al ≡ neg al
![Page 40: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/40.jpg)
two's complement
● neg eax● neg bx● neg cl● neg dh
![Page 41: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/41.jpg)
8086 FLAGS register
CF: carry flagOF: overflow flagSF: sign flagZF: zero flag
PF: parity flagDF: direction flagIF: interrupt flag
Car
ry F
lag
(CF)
Par
ity F
lag
(PF)
Aux
iliar
y C
arry
Fla
g (A
F)
Zero
Fla
g (Z
F)
Sig
n Fl
ag (S
F)
Trap
Fla
g (T
F)
Inte
rrup
t Fla
g (IF
)
Dire
ctio
n Fl
ag (D
F)
Ove
rflow
Fla
g (O
F)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
![Page 42: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/42.jpg)
8086 FLAGS register
CLC (clear carry, set CF=0) STC (set carry, set CF=1) CMC (complement carry, set CF= ~CF)CLD, STD, CLI, STI
Car
ry F
lag
(CF)
Par
ity F
lag
(PF)
Aux
iliar
y C
arry
Fla
g (A
F)
Zero
Fla
g (Z
F)
Sig
n Fl
ag (S
F)
Trap
Fla
g (T
F)
Inte
rrup
t Fla
g (IF
)
Dire
ctio
n Fl
ag (D
F)
Ove
rflow
Fla
g (O
F)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
![Page 43: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/43.jpg)
8086 FLAGS register
Car
ry F
lag
(CF)
Par
ity F
lag
(PF)
Aux
iliar
y C
arry
Fla
g (A
F)
Zero
Fla
g (Z
F)
Sig
n Fl
ag (S
F)
Trap
Fla
g (T
F)
Inte
rrup
t Fla
g (IF
)
Dire
ctio
n Fl
ag (D
F)
Ove
rflow
Fla
g (O
F)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
8086 : FLAGS (16 bits) 80386: EFLAGS (32 bits)x86-64: RFLAGS (64 bits)
![Page 44: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/44.jpg)
Overflow - unsigned integers
● add eax, ebx○ when there is carray○ carry flag (CF) is set
● sub eax, ebx○ when there is borrow○ carry flag (CF) is set
![Page 45: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/45.jpg)
Overflow - signed integers
● add eax, ebx○ when POSITIVE+POSITIVE=NEGATIVE○ when NEGATIVE+NEGATIVE=POSITIVE○ overflow flag (OF) is set
![Page 46: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/46.jpg)
Overflow
● carry flag (CF): unsigned● overflow flag (OF): signed
![Page 47: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/47.jpg)
Decreasing bit size - unsigned
0 0 A 2
4 E A 2
F F A 2
F F F 3
A 2
A 2
A 2
F 3
![Page 48: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/48.jpg)
Decreasing bit size - signed
0 0 7 2 7 2
![Page 49: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/49.jpg)
Decreasing bit size - signed
0 0 7 2
0111 00100000 0000 0111 0010
7 2
![Page 50: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/50.jpg)
Decreasing bit size - signed
0 0 7 2 7 2
0111 00100000 0000 0111 0010
114 114
![Page 51: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/51.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
![Page 52: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/52.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
1010 00100000 0000 1010 0010
![Page 53: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/53.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
1010 00100000 0000 1010 0010
162
![Page 54: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/54.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
1010 00100000 0000 1010 0010 0101 1110
2's Comp.
162
![Page 55: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/55.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
1010 00100000 0000 1010 0010
162
0101 1110
2's Comp.
94
![Page 56: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/56.jpg)
Decreasing bit size - signed
0 0 A 2 A 2
1010 00100000 0000 1010 0010
162 -94
0101 1110
2's Comp.
94
![Page 57: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/57.jpg)
Decreasing bit size - signed
4 E A 2 A 2
![Page 58: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/58.jpg)
Decreasing bit size - signed
4 E A 2 A 2
1010 00100100 1110 1010 0010
![Page 59: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/59.jpg)
Decreasing bit size - signed
F F 7 2 7 2
![Page 60: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/60.jpg)
Decreasing bit size - signed
F F 7 2 7 2
0111 00101111 1111 0111 0010
![Page 61: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/61.jpg)
Decreasing bit size - signed
F F 7 2 7 2
0111 00101111 1111 0111 0010
< 0 > 0
![Page 62: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/62.jpg)
Decreasing bit size - signed
F F A 2 A 2
![Page 63: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/63.jpg)
Decreasing bit size - signed
F F A 2 A 2
1010 00101111 1111 1010 0010
![Page 64: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/64.jpg)
Decreasing bit size - signed
F F A 2 A 2
1010 00101111 1111 1010 0010
0101 1110
2's Comp.2's Comp.
0000 0000 0101 1110
![Page 65: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/65.jpg)
Decreasing bit size - signed
F F A 2 A 2
1010 00101111 1111 1010 0010
94
0101 1110
2's Comp.2's Comp.
0000 0000 0101 1110
94
![Page 66: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/66.jpg)
Decreasing bit size - signed
F F A 2 A 2
1010 00101111 1111 1010 0010
-94 -94
![Page 67: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/67.jpg)
Decreasing bit size - signed
F F F F F F
![Page 68: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/68.jpg)
Decreasing bit size - signed
F F F F F F
1111 11111111 1111 1111 1111
![Page 69: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/69.jpg)
Decreasing bit size - signed
F F F F F F
1111 11111111 1111 1111 1111
0000 0001
2's Comp.2's Comp.
0000 0000 0000 0001
![Page 70: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/70.jpg)
Decreasing bit size - signed
F F F F F F
1111 11111111 1111 1111 1111
1
0000 0001
2's Comp.2's Comp.
0000 0000 0000 0001
1
![Page 71: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/71.jpg)
Decreasing bit size - signed
F F F F F F
1111 11111111 1111 1111 1111
-1 -1
![Page 72: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/72.jpg)
Decreasing bit size - signed
0 0 7 2
4 E A 2F F A 2
F F F F
0 0 A 2
F F 7 2
![Page 73: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/73.jpg)
Extending bit size - unsigned
7 2
7 2
F F
A 2
![Page 74: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/74.jpg)
Extending bit size - unsigned
0 0 7 2
0 0 7 2
0 0 F F
7 2
7 2
F F
0 0 A 2A 2
![Page 75: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/75.jpg)
Extending bit size - unsigned
● AX <- AL mov ah, 0● EAX <- AX movzx eax, ax● EAX <- AL movzx eax, al● AX <- AL movzx ax, al● EAX <- BX movzx eax, bx● RAX <- EAX movzx rax, eax (64 bit)
![Page 76: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/76.jpg)
Extending bit size - signed
0000 0000 0111 0010
1111 1111 1010 0010
![Page 77: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/77.jpg)
Extending bit size - signed
0000 0000 0111 0010
1111 1111 1010 0010
repeat the sign bit
![Page 78: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/78.jpg)
Extending bit size - signed
0 2
7 2
F F
8 2
![Page 79: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/79.jpg)
Extending bit size - signed
0 0 0 2
0 0 7 2
F F F F
0 2
7 2
F F
F F 8 28 2
![Page 80: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/80.jpg)
Extending bit size - signed
● AX <- AL CBW (convert Byte to Word) ● EAX <- AX CWDE (convert Word to double word extended)● RAX <- EAX CDQE (convert Double to Quad extended,64 bit)
● DX:AX <- AX CWD (convert Word to Double word) ● EDX:EAX <- EAX CDQ (convert Double word to Quad word) ● RDX:RAX <- RAX CQO (convert Quad word to Oct Word, 64 bit)
![Page 81: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/81.jpg)
Data size names
● Byte (8 bit)● Word (2 bytes)● Double word (4 bytes)● Quad word (8 bytes)● Oct word (16 bytes)
![Page 82: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/82.jpg)
Extending bit size - signed
● EAX <- AX movsx eax, ax● EAX <- AL movsx eax, al● AX <- AL movsx ax, al● EAX <- BX movsx eax, bx● RAX <- EAX movsx rax, eax (64 bit)
![Page 83: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/83.jpg)
ADC and SBB
● ADC: add with carry○ ADC dest, src dest = dest + src + CF
● SBB: subtract with borrow○ SBB dest, src dest = dest - src - CF
● Example:○ edx:eax = edx:eax + ecx:ebx
![Page 84: Assembly - K. N. Toosi University of Technology · 2019. 11. 13. · Assembly Lecture 4 Binary, Decimal and Hex Integer representation, signed integers, x86 flags, extending bit size](https://reader035.vdocuments.site/reader035/viewer/2022071512/6132a80ddfd10f4dd73a9766/html5/thumbnails/84.jpg)
ADC and SBB
● ADC: add with carry○ ADC dest, src dest = dest + src + CF
● SBB: subtract with borrow○ SBB dest, src dest = dest - src - CF
● Example:○ edx:eax = edx:eax + ecx:ebx
■ add eax, ebx■ adc edx, ecx