Definition udiv := {|
c_source :=
"#include ""stdint.h""
typedef struct {
uint32_t quot; …" ;
riscv_elf :=
[x7f; x45; x4c; x46; x01; x01; x01; x00; x00; x00; x00; x00; x00; x00; x00; x00;
x02; x00; xf3; x00; x01; x00; x00; x00; x54; x00; x01; x00; x34; x00; x00; x00;
x0c; x02; x00; x00; x00; x00; x00; x00; x34; x00; x20; x00; x01; x00; x28; x00;
x06; x00; x05; x00; x01; x00; x00; x00; x00; x00; x00; x00; x00; x00; x01; … ] |}.
Compute udiv.(c_source).= #include "stdint.h"
typedef struct {
uint32_t quot;
uint32_t rem;
} udiv_t;
udiv_t udiv ( uint32_t num, uint32_t denom) {
uint32_t q = 0 ;
while ( num >= denom) {
num -= denom; ++q;
}
return ( udiv_t) { . rem = num, . quot = q };
} : string
Compute udiv.(riscv_elf).= 00010054 < udiv >:
10054: 00 05 07 93 mv a5 , a0
10058: ff 01 01 13 addi sp , sp ,- 16
1005c: 00 00 05 13 li a0 , 0
10060: 00 b7 f8 63 bgeu a5 , a1 , 10070 < udiv + 0x1c >
10064: 00 07 85 93 mv a1 , a5
10068: 01 01 01 13 addi sp , sp , 16
1006c: 00 00 80 67 ret
10070: 40 b7 87 b3 sub a5 , a5 , a1
10074: 00 15 05 13 addi a0 , a0 , 1
10078: fe 9f f0 6f j 10060 < udiv + 0xc >
: list Byte.byte