/*测试adds, cmp以及adc指令的条件标志位
*/
.global add_inst_test
add_inst_test:mov x0, #0ldr x1, =0xffffffffffffffffmov x2, #3/*测试adds的进位功能,当有溢出发生时,C=1*/adds x0, x1, x1adc x3, xzr, xzr/*测试cmp的条件标志位,当x1 > x2时,C=1当x1 < x2是, C=0*/cmp x1, x2adc x4, xzr, xzrret
ADDS: Add (extended register), setting flags, adds a register value and a sign or zero-extended register value, followed by an optional left shift amount, and writes the result to the destination register. The argument that is extended from the register can be a byte, halfword, word, or doubleword. It updates the condition flags based on the result.
CMP:This instruction is an alias of the SUBS (shifted register) instruction.
ret = compare_and_return(10, 9);
val = compare_and_return(9, 10);/*当arg1 >= arg2 时, 返回 0当arg1 < arg2 时,返回0xffffffffffffffff
*/
.global compare_and_return
compare_and_return:cmp x0, x1sbc x0, xzr, xzrret
2.1.3.1 示例代码
/*data_process_instr lab3: 测试ands指令对Z标志位的影响
*/
.global ands_test
ands_test:mov x1, #0x3mov x2, #0//mov x2, #2ands x3, x1, x2/*读取NZCV寄存器,查看Z标志位是否为1, 见armv8.6手册第C5.2.9章*/mrs x0, nzcvret
/*data_process_instr lab4: 测试位段bitfield指令*/
.global bitfield_test
bitfield_test:/* 位段插入*/mov x1, 0x345mov x0, 0bfi x0, x1, 8, 4/*无符号数的bitfield提取,提取x2,从第4个bit开始,提取8位,x3其他位都是0,最终:0xbc*/ldr x2, =0x5678abcdubfx x3, x2, #4, #8/*有符号数的bitfield提取,提取x2,从第4个bit开始,提取8bit。x4的其他比特位都是f, 最终:0xffffffffffffffbc*/sbfx x4, x2, #4, #8ret
BFI :Bitfield Insert copies a bitfield of bits from the least significant bits of the source register to bit position of the destination register, leaving the other destination bits unchanged.
UBFX :Unsigned Bitfield Extract copies a bitfield of bits starting from bit position in the source register to the least significant bits of the destination register, and sets destination bits above the bitfield to zero.
/*data_process_instr lab4: 测试位段bitfield指令*/
.global bitfield_test
bitfield_test:/* 位段插入*/mov x1, 0x345mov x0, 0bfi x0, x1, 8, 4/*无符号数的bitfield提取,提取x2,从第4个bit开始,提取8位,x3其他位都是0,最终:0xbc*/ldr x2, =0x5678abcdubfx x3, x2, #4, #8/*有符号数的bitfield提取,提取x2,从第4个bit开始,提取8bit。x4的其他比特位都是f, 最终:0xffffffffffffffbc*/sbfx x4, x2, #4, #8/*lab5: 使用ubfx指令来读取 寄存器的位域*/mrs x1, ID_AA64ISAR0_EL1/*读取atomic域的值:判断是否支持LSE指令*/ubfx x0, x1, #20, #4/*读取AES域的值:判断是否支持AES指令*/ubfx x2, x1, #4, #4ret
2.5.1.2 测试之前的状态
2.5.1.3 测试之后的状态值