Quick actions

cmd+k|ctrl+k

Navigation

Languages

asssssssm

Snippet info

Language

Cpp

Visibility

public

Author

hyrious

Created

2020-02-16T13:40:12Z

Updated

2020-02-16T13:40:12Z

#include <cstdint>
#include <cstdio>
using namespace std;

struct Register {
    uint32_t value = 0;

    uint8_t *l = (uint8_t *)&value;
    uint8_t *h = (uint8_t *)&value + 1;
    uint16_t *x = (uint16_t *)&value;
    uint32_t *e = &value;
};

int main() {
    Register eax, ecx, edx, ebx;

#define ax (*(eax.x))
#define dx (*(edx.x))
#define cx (*(ecx.x))
#define cl (*(ecx.l))

    // mov ax,1234h
    ax = 0x1234;
    // mov cl,3
    cl = 4;
    // rol ax,cl
    ax = (ax << cl) | (ax >> (16 - cl));
    // dec ax
    ax--;
    // mov cx,4
    cx = 4;
    // mul cx
    uint32_t ret = ax * cx;
    ax = (uint16_t)ret;
    dx = (uint16_t)(ret >> 16);

    printf("ax = %#x\n", ax);
}
INFO