3. Multiplication and Division Instruction
1) MUL
unsigned integer multiplication
1> 형식 및 사용
MUL operand
- al/ax/eax와 operand를 곱해서 ax/dx:ax/edx:eax에 저장한다. (결과는 2배의 자리로 저장한다.)
- 특히 16bit와 32bit인 경우는 2개의 register를 이용해서 값을 저장한다.
2> 규칙
- size를 맞춰줘야 한다.
- al/ax/eax와 operand 모두 unsigned integer여야 한다.
- operand 자리에는 register 혹은 memory가 와야한다.
2) IMUL
signed integer multiplication
1> 형식
3) DIV
unsigned integer divider
1> 형식 및 사용
DIV operand
- 'ax/dx:ax/edx:eax ÷ operand' 작업을 한다.
- 수식 : ax/dx:ax/edx:eax = al/ax/eax * operand + ah/dx/edx
2> 규칙
- size를 맞춰줘야 한다.
- al/ax/eax와 operand 모두 unsigned integer여야 한다.
- operand 자리에는 register 혹은 memory가 와야한다.
- 연산 결과 각 Quotient와 Remainder에 bit를 초과하는 숫자가 오면 프로그램이 죽을 수 있다.
4) Signed Integer Division
0> 나눗셈을 하기전에 sign-extension이 필요한다.
low(확장의 대상)의 sign bit를 복사하여 high(확장 이후 생기는 bit들)에 할당한다.
1> CBW, CWD, CDQ
bit의 자리수 별 sign extention instruction
- CBW : al을 ah까지 확장한다. (BYTE -> WORD)
- CWD : ax을 dx까지 확장한다. (WORD -> double WORD)
- CDQ : eax을 edx까지 확장한다. (DWORD -> QWORD)
2> IDIV
signed integer divide
- 모든 형식과 규칙이 DIV와 동일합니다.
- 다만 사용 전에 sign extentsionㅇ르 진행합니다.
- dividend가 음수이면 remainder도 음수이다. (??)
4) 기타 참고할 것
1> Unsigned Arithmetic Expressions
중간중간 carry flag를 확인할 필요가 있다.
- 예제 : var4 = (var1 + var2) * var3
2> Signed Arithmetic Expressions
중간 중간 overflow flag를 확인할 필요가 있다.
'Assembly' 카테고리의 다른 글
8-1강 - Advanced Procedures 1 (Stack Frames) (0) | 2020.06.23 |
---|---|
7-3강 - Integer Arithmetic 3 (Exteded addition & subtraction) (0) | 2020.06.23 |
7-1강 - Integer Arithmetic 1 (shift와 rotate) (0) | 2020.06.06 |
6-3강 - Conditional Processing 3 (Conditional Structures 조건문) (0) | 2020.06.06 |
6-2강 - Conditional Processing 2 (conditional jump, loop) (0) | 2020.06.05 |