43 lines
1.1 KiB
NASM
43 lines
1.1 KiB
NASM
|
bits 64
|
||
|
|
||
|
SECTION .data
|
||
|
; empty
|
||
|
|
||
|
SECTION .text
|
||
|
global _start
|
||
|
_start:
|
||
|
%include "header.asm.inc"
|
||
|
|
||
|
; multiplication: 2 * 0xFFFFFFFF
|
||
|
mov eax, 2 ; 2
|
||
|
mov edx, 0xFFFFFFFF ; (2^32)-1
|
||
|
mul edx ; edx:eax = eax * edx
|
||
|
; edx becomes 0x1 (LSB is 1)
|
||
|
; eax becomes 0xFFFFFFFE (LSB is 0)
|
||
|
|
||
|
|
||
|
; caveat: EDX is cleared even if even multiplaction
|
||
|
; does not require it
|
||
|
; e.g., multiply 2 * 4
|
||
|
mov edx, 0x11223344 ; init with random value
|
||
|
mov eax, 2 ; 2 (first factor, implicit)
|
||
|
mov ebx, 4 ; 4 (second factor, explicit)
|
||
|
mul ebx ; eax = 8, edx = 0
|
||
|
|
||
|
|
||
|
; multiplication with signed integers
|
||
|
mov bl, -3 ; -3 or 0xFD
|
||
|
|
||
|
mov al, -2 ; -2 or 0xFE
|
||
|
mul bl ; dl:al = bl * al (unsigned)
|
||
|
|
||
|
mov al, -2 ; -2 or 0xFE
|
||
|
imul bl ; dl:al = bl * al (signed)
|
||
|
|
||
|
; challenge: (2^32)-1 * 2^8
|
||
|
mov eax, 0xffffffff
|
||
|
mov edx, 0x100
|
||
|
mul edx
|
||
|
|
||
|
%include "sysexit.asm.inc"
|