forked from cirosantilli/x86-assembly-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mul.asm
64 lines (48 loc) · 954 Bytes
/
mul.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
; # mul
; Unsigned multiply.
; After:
; mul SRC
; For 16 bits and up:
; DX:AX = AX * SRC;
; And for 8 bits:
; AX = AL * SRC;
; No immediate form, although imul has.
; http://stackoverflow.com/questions/20499141/is-it-possible-to-multiply-by-and-immediate-with-mul-in-x86-assembly/33202309#33202309
%include "lib/asm_io.inc"
DATA
x: dd 0x12341234
ENTRY
mov eax, 2
mov ebx, 2
mul ebx
ASSERT_EQ 4
ASSERT_EQ ebx, 2
; 8 bit
mov eax, 0
mov al, 2
mov bl, 0x80
mov dl, 0
mul bl
ASSERT_EQ 0x100
; 16 bit
mov eax, 0
mov edx, 0
mov ax, 2
mov bx, 0x8000
mov dx, 0
mul bx
ASSERT_EQ 0
mov ax, dx
ASSERT_EQ 1
; 32 bit
mov eax, 2
mov ebx, 0x80000000
mov edx, 0
mul ebx
ASSERT_EQ 0
ASSERT_EQ edx, 1
; Memory version
mov eax, 2
mul dword [x]
ASSERT_EQ 0x24682468
EXIT