NAME=rz-asm i4004
FILE=-
CMDS=<<EOF
!!rz-asm -L~4004
EOF
EXPECT=<<EOF
_dAe  4          i4004       LGPL3   Intel 4004 microprocessor
EOF
RUN

NAME=rz-asm arm asm/dis endian
FILE=-
CMDS=<<EOF
!rz-asm -a arm -b32 "mov r0, 3"
!rz-asm -a arm -b32 -e "mov r0, 3"
!rz-asm -a arm -b32 -d 0300a0e3
!rz-asm -a arm -b32 -e -d e3a00003
EOF
EXPECT=<<EOF
0300a0e3
e3a00003
mov r0, 3
mov r0, 3
EOF
RUN

NAME=1: rz-asm
FILE=-
CMDS=!rz-asm -a arm -b32 "mov r0, 3"
EXPECT=<<EOF
0300a0e3
EOF
RUN

NAME=rz-asm blx arm/thumb
FILE=-
CMDS=!rz-asm -o 0x4000 -a arm -b 16 -d 80f018ea
EXPECT=<<EOF
blx 0x84434
EOF
RUN

NAME=rz-asm blx arm/thumb 2
FILE=-
CMDS=!rz-asm -o 0x4000 -a arm -b 16 -d 80f018ea
EXPECT=<<EOF
blx 0x84434
EOF
RUN

NAME=rz-asm arm/thumb branch errors
BROKEN=1 # Only on Windows
FILE=-
CMDS=<<EOF
!rz-asm -a arm -b 16 'b.n 8'
!rz-asm -a arm -b 16 'b.w 8'
!rz-asm -a arm -b 16 'bl 8'
!rz-asm -a arm -b 16 'blx 8'
!rz-asm -a arm -b 16 'b.n 9'
!rz-asm -a arm -b 16 'b.w 9'
!rz-asm -a arm -b 16 'bl 9'
!rz-asm -a arm -b 16 'blx 9'
!rz-asm -a arm -b 16 'b.w 0x1000000'
!rz-asm -a arm -b 16 'bl 0x1000000'
!rz-asm -a arm -b 16 'blx 0x1000000'
!rz-asm -a arm -b 16 'b.w 0x1000004'
!rz-asm -a arm -b 16 'bl 0x1000004'
!rz-asm -a arm -b 16 'blx 0x1000004'
EOF
EXPECT=<<EOF
02e0
00f002b8
00f002f8
00f002e8
fff3fe97
fff3fed7
fff3fec7
EOF
RUN

NAME=2: rz-asm
FILE=-
CMDS=!rz-asm -a x86 -b 64 -d "5589e583ec2083f8000f8507000000b800000000eb05b80100000083c4205dc3"
EXPECT=<<EOF
push rbp
mov ebp, esp
sub esp, 0x20
cmp eax, 0
jne 0x16
mov eax, 0
jmp 0x1b
mov eax, 1
add esp, 0x20
pop rbp
ret
EOF
RUN

NAME=rz-asm #1167
FILE=-
CMDS=!rz-asm -a x86 -b 64 "cmp rax,rbx"
EXPECT=<<EOF
4839d8
EOF
RUN

NAME=rz-asm #1167 2
FILE=-
CMDS=!rz-asm -a x86 -b 64 "test rax, rbx"
EXPECT=<<EOF
4885d8
EOF
RUN

NAME=rz-asm #1167 3
FILE=-
BROKEN=1
CMDS=!rz-asm -s att -a x86.as -b 64 "test %rbx, %rax"
EXPECT=<<EOF
4885d8
EOF
RUN

NAME=rz-asm #1167 4
FILE=-
BROKEN=1
CMDS=!rz-asm -s intel -a x86.as -b 64 "test rax, rbx"
EXPECT=<<EOF
4885d8
EOF
RUN

NAME=rz-asm #1167 5
BROKEN=1
FILE=-
CMDS=!rz-asm -s att -a x86.as -b 64 'add $33, %rbx'
EXPECT=<<EOF
4883c321
EOF
RUN

NAME=rz-asm #1167 6
FILE=-
CMDS=!rz-asm -s intel -a x86.as -b 64 "add rbx, 33"
EXPECT=<<EOF
4883c321
EOF
RUN

NAME=rz-asm #1900
FILE=-
CMDS=<<EOF
!rz-asm -a x86 -b 32 "mov [0x33], eax"
!rz-asm -a x86 -b 32 "mov eax, 33"
!rz-asm -a x86 -b 32 "mov eax, 0x33"
EOF
EXPECT=<<EOF
890533000000
b821000000
b833000000
EOF
RUN

NAME=rz-asm #1900 (detect syntax error - case 1)
FILE=-
CMDS=!rz-asm -a x86 -b 32 "mov hello, eax"
EXPECT=<<EOF
EOF
EXPECT_ERR=<<EOF
Cannot assemble 'mov hello, eax' at line 3
invalid
EOF
RUN

NAME=rz-asm #1900 (detect syntax error - case 2)
FILE=-
CMDS=!rz-asm -a x86 -b 32 "mov 33, eax"
EXPECT=<<EOF
EOF
EXPECT_ERR=<<EOF
Cannot assemble 'mov 33, eax' at line 3
invalid
EOF
RUN

NAME=rz-asm #1900 (detect syntax error - case 3)
FILE=-
CMDS=!rz-asm -a x86 -b 32 "mov eax, hello"
EXPECT=<<EOF
EOF
EXPECT_ERR=<<EOF
Cannot assemble 'mov eax, hello' at line 3
invalid
EOF
RUN

NAME=rz-asm x86_32 overlarge operand
FILE=-
CMDS=!rz-asm -a x86 -b 32 "mov eax, 0x1122334455"
EXPECT=
EXPECT_ERR=<<EOF
Cannot assemble 'mov eax, 0x1122334455' at line 3
invalid
EOF
RUN

NAME=rz-asm x86_64 overlarge operand
FILE=-
CMDS=<<EOF
!rz-asm -a x86 -b 64 "mov rax, 0x112233445566778899"
!rz-asm -a x86 -b 64 "mov eax, 0x1122334455"
EOF
EXPECT=
EXPECT_ERR=<<EOF
Cannot assemble 'mov rax, 0x112233445566778899' at line 3
invalid
Cannot assemble 'mov eax, 0x1122334455' at line 3
invalid
EOF
RUN

NAME=rz-asm #9197
FILE=-
CMDS=!rz-asm -a arm -b 64 "ldur x1, [x29, -8]"
EXPECT=<<EOF
a1835ff8
EOF
RUN

NAME=rz-asm -h~Usage?"
FILE=-
CMDS=!!rz-asm -h~Usage?
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-asm -C
FILE=-
CMDS=!rz-asm -C -a x86 -b 32 "mov eax, 33"
EXPECT=<<EOF
"\xb8\x21\x00\x00\x00"
EOF
RUN

NAME=rz-asm -d
FILE=-
CMDS=!rz-asm -d -a x86 -b 32 "b821000000"
EXPECT=<<EOF
mov eax, 0x21
EOF
RUN

NAME=rz-asm -D
FILE=-
CMDS=!rz-asm -D -a x86 -b 32 "b821000000"
EXPECT=<<EOF
0x00000000   5               b821000000  mov eax, 0x21
EOF
RUN

NAME=rz-asm -s
FILE=-
CMDS=!rz-asm -s att -a x86 -b 32 -D "31ed"
EXPECT=<<EOF
0x00000000   2                     31ed  xorl %ebp, %ebp
EOF
RUN

NAME=rz-asm -o
FILE=-
CMDS=!rz-asm -s att -o 0xa -a x86 -b 32 -D "31ed"
EXPECT=<<EOF
0x0000000a   2                     31ed  xorl %ebp, %ebp
EOF
RUN

NAME=rz-asm -F pseudo
FILE=-
CMDS=!rz-asm -a x86 -b 32 -o 0xa -F x86.pseudo -D 31ed
EXPECT=<<EOF
0x0000000a   2                     31ed  ebp = 0
EOF
RUN

NAME=rz-asm -F
FILE=-
CMDS=!rz-asm -o 0xa -a x86 -b 32 -D 31ed
EXPECT=<<EOF
0x0000000a   2                     31ed  xor ebp, ebp
EOF
RUN

NAME=rz-asm -F -o order bug
FILE=-
CMDS=!rz-asm -a x86 -b 32 -o 0xa -D 31ed
EXPECT=<<EOF
0x0000000a   2                     31ed  xor ebp, ebp
EOF
RUN

NAME=rz-asm -B
FILE=-
CMDS=!rz-asm -a x86 -b16 -B "xor al, 0x34";ps
EXPECT=<<EOF
44
EOF
RUN

NAME=rz-asm -s att -a x86.as -b 64 movq %rdx, %rax
FILE=-
CMDS=!rz-asm -s att -a x86.as -b 64 "movq %rdx, %rax"
EXPECT=<<EOF
4889d0
EOF
RUN

NAME=rz-asm -v~commit?"
FILE=-
CMDS=!!rz-asm -v~commit?
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-asm -w
FILE=-
CMDS=!rz-asm -w -a x86 -b 32 "mov"
EXPECT=<<EOF
moves data from src to dst
EOF
RUN

NAME=rz-asm  dissassemble ARM32 binary file
FILE=-
CMDS=!rz-asm -DB -a arm -o 0x200 -b 32 -f bins/other/rz-asm/testARM32.bin
EXPECT=<<EOF
0x00000200   4                 4661b0e1  asrs r6, r6, 2
0x00000204   4                 f087bd08  popeq {r4, r5, r6, r7, r8, sb, sl, pc}
0x00000208   4                 0040a0e3  mov r4, 0
0x0000020c   4                 014084e2  add r4, r4, 1
0x00000210   4                 043095e4  ldr r3, [r5], 4
0x00000214   4                 0920a0e1  mov r2, sb
0x00000218   4                 0810a0e1  mov r1, r8
0x0000021c   4                 0700a0e1  mov r0, r7
0x00000220   4                 33ff2fe1  blx r3
0x00000224   4                 060054e1  cmp r4, r6
EOF
RUN

NAME=rz-asm  dissassemble ARM32 binary file with skip
FILE=-
CMDS=!rz-asm -DB -a arm -o 0x200 -b 32 -f bins/other/rz-asm/testARM32.bin -i 4
EXPECT=<<EOF
0x00000200   4                 f087bd08  popeq {r4, r5, r6, r7, r8, sb, sl, pc}
0x00000204   4                 0040a0e3  mov r4, 0
0x00000208   4                 014084e2  add r4, r4, 1
0x0000020c   4                 043095e4  ldr r3, [r5], 4
0x00000210   4                 0920a0e1  mov r2, sb
0x00000214   4                 0810a0e1  mov r1, r8
0x00000218   4                 0700a0e1  mov r0, r7
0x0000021c   4                 33ff2fe1  blx r3
0x00000220   4                 060054e1  cmp r4, r6
EOF
RUN

NAME=rz-asm endian test 1
FILE=-
CMDS=!rz-asm -e -a arm -b 32 -d 0ad0a0e1
EXPECT=<<EOF
beq 0xff42838c
EOF
RUN

NAME=rz-asm endian test 2
FILE=-
CMDS=!rz-asm -e -a arm -b 32 -d fff0a0e3
EXPECT=<<EOF
invalid
EOF
RUN

NAME=rz-asm  SPP include directive
FILE=-
CMDS=!rz-asm -a x86 -b 32 -p -f bins/other/rz-asm/asm/include.asm
EXPECT=<<EOF
9083e803bb00000000cd80c3
EOF
RUN

NAME=rz-asm  SPP nested conditionals
FILE=-
CMDS=!rz-asm -a x86 -b 32 -p -f bins/other/rz-asm/asm/nest.asm
EXPECT=<<EOF
83c10283e90583c301b90200000090
EOF
EXPECT_ERR=<<EOF
WARNING: WARN (line=1)
ERROR: ERR (line=1)
EOF
RUN

NAME=rz-asm x86.asm.32
FILE=-
CMDS=!rz-asm -f bins/elf/analysis/hello.asm
EXPECT=<<EOF
ba0e000000b91d000000bb01000000b804000000cd80b801000000cd8048656c6c6f2c20776f726c64210a00
EOF
RUN

NAME=rz-asm bswap x64 #8095
FILE=-
CMDS="!rz-asm -a x86 -b 64 \"bswap rax;bswap rbx;bswap rcx;bswap rdx\""
EXPECT=<<EOF
480fc8480fcb480fc9480fca
EOF
RUN

NAME=rz-asm bswap x64 #8095 (with single quotes)
BROKEN=1 # Only on Windows
FILE=-
CMDS=!rz-asm -a x86 -b 64 'bswap rax;bswap rbx;bswap rcx;bswap rdx'
EXPECT=480fc8480fcb480fc9480fca
RUN

NAME=rz-asm mov eax, [eax * 2 + 8]
FILE=-
CMDS=!rz-asm -a x86 -b 32 "mov eax, [eax * 2 + 8]"
EXPECT=<<EOF
8b044508000000
EOF
RUN

NAME=rz-asm -a x86 -b 64 -A 0x55
FILE=-
CMDS=!rz-asm -a x86 -b 64 -A 0x55
EXPECT=<<EOF
offset:   0x00000000
bytes:    55
type:     rpush
stackop:  unknown
esil:     rbp,8,rsp,-,=[8],8,rsp,-=
stackptr: 8

EOF
RUN

NAME=rz-asm -c
FILE=-
CMDS=!rz-asm -a arm -b 16 -d -c cortex 0x80f30988
EXPECT=<<EOF
msr psp, r0
EOF
RUN

NAME=rz-asm -k
BROKEN=1
FILE=-
CMDS=!rz-asm -k darwin 0x90
EXPECT=<<EOF
EOF
RUN

NAME=rz-asm -a x86 -b 64 -E 0x55
FILE=-
CMDS=!rz-asm -a x86 -b 64 -E 0x55
EXPECT=<<EOF
rbp,8,rsp,-,=[8],8,rsp,-=
EOF
RUN

NAME=rz-asm -a x86 -b 64 -Aj 0x55
FILE=-
CMDS=!rz-asm -a x86 -b 64 -Aj 0x55
EXPECT=<<EOF
[{"opcode":0,"bytes":"55","type":"rpush","stackop":"unknown","esil":"rbp,8,rsp,-,=[8],8,rsp,-=","stackptr":8}]
EOF
RUN

NAME=rz-asm -L
FILE=-
CMDS=!rz-asm -L | grep -c arm.gnu
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-asm -qL
FILE=-
CMDS=!rz-asm -qL | grep -c arm.gnu
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-asm -v
FILE=-
CMDS=!rz-asm -v  | grep -c build
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-asm -a x86 -b 64 -r push ebp
FILE=-
CMDS=!rz-asm -a x86 -b 64 -r push ebp
EXPECT=<<EOF
e asm.arch=x86
e asm.bits=64
wx 6a00
f entry = $$
f label.main = $$ + 1
EOF
RUN

NAME=rz-asm -a sh -e -d
FILE=-
CMDS=!rz-asm -a sh -e -d "8d00 000b 2029 8ffb 0009 420b 31e0"
EXPECT=<<EOF
bt.s 0x00000004
rts
and r2, r0
bf.s 0x00000000
nop
jsr @r2
cmp/eq r14, r1
EOF
RUN

NAME=rz-asm -a sh -e -D
FILE=-
CMDS=!rz-asm -a sh -e -D "8d00 000b 2029 8ffb 0009 420b 31e0"
EXPECT=<<EOF
0x00000000   2                     8d00  bt.s 0x00000004
0x00000002   2                     000b  rts
0x00000004   2                     2029  and r2, r0
0x00000006   2                     8ffb  bf.s 0x00000000
0x00000008   2                     0009  nop
0x0000000a   2                     420b  jsr @r2
0x0000000c   2                     31e0  cmp/eq r14, r1
EOF
RUN

NAME=rz-asm -a sh -d
FILE=-
CMDS=!rz-asm -a sh -d "008d 0b00 2920 fb8f 0900 0b42 e031"
EXPECT=<<EOF
bt.s 0x00000004
rts
and r2, r0
bf.s 0x00000000
nop
jsr @r2
cmp/eq r14, r1
EOF
RUN

NAME=rz-asm -a sh -D
FILE=-
CMDS=!rz-asm -a sh -D "008d 0b00 2920 fb8f 0900 0b42 e031"
EXPECT=<<EOF
0x00000000   2                     008d  bt.s 0x00000004
0x00000002   2                     0b00  rts
0x00000004   2                     2920  and r2, r0
0x00000006   2                     fb8f  bf.s 0x00000000
0x00000008   2                     0900  nop
0x0000000a   2                     0b42  jsr @r2
0x0000000c   2                     e031  cmp/eq r14, r1
EOF
RUN

NAME=rz-asm -a ppc.as -b 64 "std r31, -8(r1)"
FILE=-
BROKEN=1
CMDS=!rz-asm -a ppc.as -b 64 "std r31, -8(r1)"
EXPECT=<<EOF
f8ffe1fb
EOF
RUN

NAME=rz-asm -a ppc -b 64 -d f8ffe1fb
FILE=-
CMDS=!rz-asm -a ppc -b 64 -d f8ffe1fb
EXPECT=<<EOF
std r31, -8(r1)
EOF
RUN

NAME=rz-asm -a ppc.as -b 32 -e "mr r10, r4"
FILE=-
BROKEN=1
CMDS=!rz-asm -a ppc.as -b 32 -e "mr r10, r4"
EXPECT=<<EOF
7c8a2378
EOF
RUN

NAME=rz-asm -a ppc -b 32 -d 78238a7c
FILE=-
CMDS=!rz-asm -a ppc -b 32 -d 78238a7c
EXPECT=<<EOF
mr r10, r4
EOF
RUN

NAME=rz-asm -a arm.as -b 16 "wfe"
FILE=-
BROKEN=1
CMDS=!rz-asm -a arm.as -b 16 "wfe"
EXPECT=<<EOF
20bf
EOF
RUN

NAME=rz-asm -a arm.as -b 32 "add fp, sp, 0"
FILE=-
BROKEN=1
CMDS=!rz-asm -a arm.as -b 32 "add fp, sp, 0"
EXPECT=<<EOF
00b08de2
EOF
RUN

NAME=rz-asm -a arm.as -b 32 -e "ldr fp, [sp], 4"
FILE=-
BROKEN=1
CMDS=!rz-asm -a arm.as -b 32 -e "ldr fp, [sp], 4"
EXPECT=<<EOF
e49db004
EOF
RUN

NAME=rz-asm -a arm.as -b 64 "sub sp, sp, 16"
FILE=-
BROKEN=1
CMDS=!rz-asm -a arm.as -b 64 "sub sp, sp, 16"
EXPECT=<<EOF
ff4300d1
EOF
RUN
