NAME=rz-asm i4004
TOOL=rz-asm
ARGS=-L
REGEXP_FILTER_OUT=.+i4004.+
EXIT_STATUS=1
EXPECT=<<EOF
_dA__ 4          i4004       LGPL3   Intel 4004 disassembler
EOF
RUN

NAME=rz-asm arm32le assemble
TOOL=rz-asm
FILE=mov r0, 3
ARGS=-a arm -b32
EXPECT=<<EOF
0300a0e3
EOF
RUN

NAME=rz-asm arm32be assemble
TOOL=rz-asm
FILE=mov r0, 3
ARGS=-a arm -b32 -e
EXPECT=<<EOF
e3a00003
EOF
RUN

NAME=rz-asm arm32le disassemble
TOOL=rz-asm
ARGS=-a arm -b32 -d 0300a0e3
EXPECT=<<EOF
mov r0, 3
EOF
RUN

NAME=rz-asm arm32be disassemble
TOOL=rz-asm
ARGS=-a arm -b32 -e -d e3a00003
EXPECT=<<EOF
mov r0, 3
EOF
RUN

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

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

NAME=2: rz-asm
TOOL=rz-asm
ARGS=-a x86 -b 64 -d 5589e583ec2083f8000f8507000000b800000000eb05b80100000083c4205dc3
EXPECT=<<EOF
push rbp
mov ebp, esp
sub esp, 0x20
cmp eax, 0x00
jnz 0x16
mov eax, 0x00
jmp 0x1b
mov eax, 0x01
add esp, 0x20
pop rbp
ret
EOF
RUN

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

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

NAME=rz-asm #1900 (detect syntax error - case 1)
TOOL=rz-asm
FILE=mov hello, eax
ARGS=-a x86 -b 32
EXIT_STATUS=1
EXPECT=
EXPECT_ERR=<<EOF
ERROR: Cannot assemble 'mov hello, eax' at line 3
EOF
RUN

NAME=rz-asm #1900 (detect syntax error - case 2)
TOOL=rz-asm
FILE=mov 33, eax
ARGS=-a x86 -b 32
EXIT_STATUS=1
EXPECT=
EXPECT_ERR=<<EOF
ERROR: Cannot assemble 'mov 33, eax' at line 3
EOF
RUN

NAME=rz-asm #1900 (detect syntax error - case 3)
TOOL=rz-asm
FILE=mov eax, hello
ARGS=-a x86 -b 32
EXIT_STATUS=1
EXPECT=
EXPECT_ERR=<<EOF
ERROR: Cannot assemble 'mov eax, hello' at line 3
EOF
RUN

NAME=rz-asm x86_32 overlarge operand
TOOL=rz-asm
FILE=mov eax, 0x1122334455
ARGS=-a x86 -b 32
EXIT_STATUS=1
EXPECT=
EXPECT_ERR=<<EOF
ERROR: Cannot assemble 'mov eax, 0x1122334455' at line 3
EOF
RUN

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

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

NAME=rz-asm -d
TOOL=rz-asm
ARGS=-d -a x86 -b 32 b821000000
EXPECT=<<EOF
mov eax, 0x21
EOF
RUN

NAME=rz-asm -D
TOOL=rz-asm
ARGS=-D -a x86 -b 32 b821000000
EXPECT=<<EOF
0x00000000   5               b821000000  mov eax, 0x21
EOF
RUN

NAME=rz-asm -s
TOOL=rz-asm
ARGS=-s att -a x86 -b 32 -D 31ed
EXPECT=<<EOF
0x00000000   2                     31ed  xor %ebp, %ebp
EOF
RUN

NAME=rz-asm -o
TOOL=rz-asm
ARGS=-s att -o 0xa -a x86 -b 32 -D 31ed
EXPECT=<<EOF
0x0000000a   2                     31ed  xor %ebp, %ebp
EOF
RUN

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

NAME=rz-asm -F
TOOL=rz-asm
ARGS=-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
TOOL=rz-asm
ARGS=-a x86 -b 32 -o 0xa -D 31ed
EXPECT=<<EOF
0x0000000a   2                     31ed  xor ebp, ebp
EOF
RUN

NAME=rz-asm -B
TOOL=rz-asm
FILE=xor al, 0x34
ARGS=-a x86 -b16 -B 
EXPECT=44
RUN

NAME=rz-asm -w
TOOL=rz-asm
ARGS=-w -a x86 -b 32 mov
EXPECT=<<EOF
moves data from src to dst
EOF
RUN

NAME=rz-asm  dissassemble ARM32 binary file
TOOL=rz-asm
FILE=bins/other/rz-asm/testARM32.bin
ARGS=-DB -a arm -o 0x200 -b 32 -f
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
TOOL=rz-asm
ARGS=-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
TOOL=rz-asm
ARGS=-e -a arm -b 32 -d 0ad0a0e1
EXPECT=<<EOF
beq 0xff42838c
EOF
RUN

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

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

NAME=rz-asm  SPP nested conditionals
TOOL=rz-asm
ARGS=-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
TOOL=rz-asm
ARGS=-f bins/elf/analysis/hello.asm
EXPECT=<<EOF
ba0e000000b91d000000bb01000000b804000000cd80b801000000cd8048656c6c6f2c20776f726c64210a00
EOF
RUN

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

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

NAME=rz-asm -a x86 -b 64 -A 0x55
TOOL=rz-asm
ARGS=-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
TOOL=rz-asm
ARGS=-a arm -b 16 -d -c cortexm 0x80f30988
EXPECT=<<EOF
msr psp, r0
EOF
RUN

NAME=rz-asm -a x86 -b 64 -E 0x55
TOOL=rz-asm
ARGS=-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
TOOL=rz-asm
ARGS=-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 -a x86 -b 64 push ebp
TOOL=rz-asm
ARGS=-a x86 -b 64 push ebp
EXPECT=<<EOF
6a00
EOF
RUN

NAME=rz-asm -a sh -e -d
TOOL=rz-asm
FILE=8d00 000b 2029 8ffb 0009 420b 31e0
ARGS=-a sh -e -d
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
TOOL=rz-asm
FILE=8d00 000b 2029 8ffb 0009 420b 31e0
ARGS=-a sh -e -D
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
TOOL=rz-asm
FILE=008d 0b00 2920 fb8f 0900 0b42 e031
ARGS=-a sh -d
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
TOOL=rz-asm
FILE=008d 0b00 2920 fb8f 0900 0b42 e031
ARGS=-a sh -D
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 -b 64 -d f8ffe1fb
TOOL=rz-asm
ARGS=-a ppc -b 64 -d f8ffe1fb
EXPECT=<<EOF
std r31, -8(r1)
EOF
RUN

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

NAME=rz-asm #1900
TOOL=rz-asm
FILE=mov [0x33], eax
ARGS=-a x86 -b 32
EXPECT=<<EOF
890533000000
EOF
RUN

NAME=rz-asm #1900
TOOL=rz-asm
FILE=mov eax, 33
ARGS=-a x86 -b 32
EXPECT=<<EOF
b821000000
EOF
RUN

NAME=rz-asm #1900
TOOL=rz-asm
FILE=mov eax, 0x33
ARGS=-a x86 -b 32
EXPECT=<<EOF
b833000000
EOF
RUN

NAME=rz-asm x86_64 overlarge operand
TOOL=rz-asm
FILE=mov rax, 0x112233445566778899
ARGS=-a x86 -b 64
EXPECT=<<EOF
48c7c0ffffffff
EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=rz-asm RzIL
TOOL=rz-asm
ARGS=-a bf -I 3e
EXPECT=<<EOF
(set ptr (+ (var ptr) (bv 64 0x1)))
EOF
EXPECT_ERR=
RUN

NAME=rz-asm RzIL failure
TOOL=rz-asm
ARGS=-a bf -I 00
EXIT_STATUS=1
EXPECT=
EXPECT_ERR=<<EOF
Invalid instruction of lifting not implemented.
EOF
RUN

NAME=rz-asm cpu mips
TOOL=rz-asm
ARGS=-m mips
EXPECT=<<EOF
mips3           MIPS III architecture.
mips1           MIPS I architecture
mips2           MIPS II architecture
mips32r2        MIPS32 Release 2 architecture
mips32r3        MIPS32 Release 3 architecture
mips32r5        MIPS32 Release 5 architecture
mips32r6        MIPS32 Release 6 architecture
mips4           MIPS IV architecture
mips5           MIPS V architecture
mips64r2        MIPS64 Release 2 architecture
mips64r3        MIPS64 Release 3 architecture
mips64r5        MIPS64 Release 5 architecture
mips64r6        MIPS64 Release 6 architecture
octeon          OCTEON architecture (also known as cnMIPS)
octeonp         OCTEON+ architecture (also known as cnMIPS+)
nanomips        nanoMIPS architecture
nms1            nanoMIPS Release 1 architecture
i7200           nanoMIPS i7200 architecture
micromips       microMIPS architecture
micro32r3       microMIPS32 Release 3 architecture
micro32r6       microMIPS32 Release 6 architecture
r2300           R2300 MIPS cpu
r2600           R2600 MIPS cpu
r2800           R2800 MIPS cpu
r2000a          R2000A MIPS cpu
r2000           R2000 MIPS cpu
r3000a          R3000A MIPS cpu
r3000           R3000 MIPS cpu
r10000          R10000 MIPS cpu
noptr64         Special MIPS configuration to disable support for 64-bit pointers
nofloat         Special MIPS configuration to disable support for floating-points
EOF
RUN

NAME=rz-asm cpu xtensa
TOOL=rz-asm
ARGS=-m xtensa
EXPECT=<<EOF
esp32           Xtensa microcontroller with Wi-Fi and Bluetooth capabilities
esp32s2         Xtensa microcontroller with Wi-Fi and USB OTG support
esp8266         Xtensa microcontroller with Wi-Fi support
EOF
RUN

NAME=rz-asm cpu arm
TOOL=rz-asm
ARGS=-m arm
EXPECT=<<EOF
v8              ARMv8 version
cortexm         ARM Cortex-M family
arm1176         ARM1176JZ(F)-S processor, ARMv6 version
cortexA72       ARM Cortex-A72 processor, ARMv8-A version
cortexA8        ARM Cortex-A8, ARMv7-A version
EOF
RUN

NAME=rz-asm cpu avr
TOOL=rz-asm
ARGS=-m avr
EXPECT=<<EOF
ATmega8         8-bit AVR microcontroller with 8KB Flash, 1KB SRAM
ATmega1280      8-bit AVR microcontroller with 128KB Flash, 8KB SRAM
ATmega1281      8-bit AVR microcontroller with 128KB Flash, 8KB SRAM
ATmega16        8-bit AVR microcontroller with 16KB Flash, 1KB SRAM
ATmega168       8-bit AVR microcontroller with 16KB Flash, 1KB SRAMs
ATmega2560      8-bit AVR microcontroller with 256KB Flash, 8KB SRAM
ATmega2561      8-bit AVR microcontroller with 256KB Flash, 8KB SRAM
ATmega328p      8-bit AVR microcontroller with 32KB Flash, 2KB SRAM
ATmega32u4      8-bit AVR microcontroller with 32KB Flash, 2.5KB SRAM
ATmega48        8-bit AVR microcontroller with 4KB Flash, 512B SRAM
ATmega640       8-bit AVR microcontroller with 64KB Flash, 8KB SRAM
ATmega88        8-bit AVR microcontroller with 8KB Flash, 1KB SRAM
ATxmega128a4u   8-bit AVR microcontroller with 128KB Flash, 8KB SRAM
ATTiny48        8-bit AVR microcontroller with 4KB Flash, 256B SRAM
ATTiny88        8-bit AVR microcontroller with 8KB Flash, 512B SRAM
EOF
RUN

NAME=rz-asm cpu m680x
TOOL=rz-asm
ARGS=-m m680x
EXPECT=<<EOF
6800            Motorola 6800: 8-bit microprocessor launched in 1974
6801            Motorola 6801: Enhanced version of the 6800 with additional features like on-chip RAM and timers.
6802            Motorola 6802: Enhanced version of the 6800 with 128 bytes of on-chip RAM and internal clock
6803            Motorola 6803: Version of 6801 without internal ROM
6805            Motorola 68HC05: 8-bit microcontroller
6808            Motorola 6808: Variant of the 6800 microprocessor
68HC08          Motorola 68HC08: 8-bit microcontroller (abbreviated as HC08)
6809            Motorola 6809: Advanced 8-bit microprocessor
6811            Motorola 68HC11: 8-bit microcontroller (also abbreviated as 6811 or HC11)
cpu12           Motorola 68HC12: 16-bit microcontroller (also abbreviated as 6812 or HC12)
6301            Hitachi 6301: 8-bit microcontroller, CMOS version of 6800
6309            Hitachi 6309: CMOS version of 6809
hcs08           Freescale HCS08: 8-bit microcontroller family
RS08            Freescale RS08: Reduced-resource version of HCS08
HCS12X          Freescale HCS12X: 16-bit microcontroller (upwards compatible with cpu12)
EOF
RUN

NAME=rz-asm cpu m68k
TOOL=rz-asm
ARGS=-m m68k
EXPECT=<<EOF
68000           Motorola 68000: 16/32-bit CISC microprocessor
68010           Motorola 68010: 16/32-bit microprocessors. Successor to Motoroloa 68000
68020           Motorola 68020: 32-bit microprocessor with added instructions and additional addressing modes
68030           Motorola 68030: Enhanced 32-bit microprocessor with integrated MMU
68040           Motorola 68040: High-performance 32-bit microprocessor with integrated FPU
68060           Motorola 68060: 32-bit microprocessor, highest performer in m68k series
cpu32           Motorola CPU32: 32-bit embedded-controller CPU core based on the 68020
coldfire        Motorola ColdFire: 32-bit embedded-controller family based on the 68000 ISA
cfv1            Motorola ColdFire V1 core
cfv2            Motorola ColdFire V2 core
cfv3            Motorola ColdFire V3 core
cfv4            Motorola ColdFire V4 core
cfv4e           Motorola ColdFire V4e core with enhanced MAC and FPU features
cfv5            Motorola ColdFire V5 core
EOF
RUN

NAME=rz-asm cpu pic
TOOL=rz-asm
ARGS=-m pic
EXPECT=<<EOF
baseline        Baseline 12-bit instruction set microcontrollers: PIC10Fxxx, PIC12Fxxx, and PIC16Fxxx
midrange        Mid-Range 14-bit instruction set microcontrollers: PIC10Fxxx, PIC12Fxxx, and PIC16Fxxx
highend         High-End 16-bit instruction set microcontrollers: PIC18Fxxxx, PIC18FxxJxx, and PIC18FxxKxx
pic18           alias for highend
EOF
RUN

NAME=rz-asm cpu ppc
TOOL=rz-asm
ARGS=-m ppc
EXPECT=<<EOF
ppc             Generic PowerPC CPU
vle             PowerPC with Variable Length Encoding extension
ps              PowerPC with Paired Single SIMD extension
qpx             PowerPC with Quad Processing eXtensions
EOF
RUN

NAME=rz-asm cpu sparc
TOOL=rz-asm
ARGS=-m sparc
EXPECT=<<EOF
v9              SPARC V9: 64-bit RISC architecture specification
EOF
RUN

NAME=rz-asm cpu tms320
TOOL=rz-asm
ARGS=-m tms320
EXPECT=<<EOF
c54x            Texas Instruments TMS320C54x DSP family
c55x            Texas Instruments TMS320C55x DSP family
c55x+           Texas Instruments TMS320C55x+ DSP family
c64x            Texas Instruments TMS320C64x DSP family
EOF
RUN

NAME=rz-asm cpu tricore
TOOL=rz-asm
ARGS=-m tricore
EXPECT=<<EOF
tricore         Generic TriCore CPU family by Infineon
EOF
RUN

NAME=rz-asm -m unknown architecture shows an error
TOOL=rz-asm
ARGS=-m ic
EXIT_STATUS=1
EXPECT_ERR=<<EOF
ERROR: Unknown asm plugin 'ic'
EOF
RUN
