/* BEGIN_LEGAL Copyright (c) 2021 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. END_LEGAL */ /// @file xed-ex3.c /// Encoder example #include "xed/xed-interface.h" #include "xed-examples-util.h" #include "xed-enc-lang.h" #include #include #include int main(int argc, char** argv); void usage(char* progname) { fprintf(stderr,"Usage: %s [-16|-32|-64] [-s16|-s32] encode-string\n", progname); exit(1); } ascii_encode_request_t parse_args(int argc, char** argv) { char const* c = 0; unsigned int i = 1; unsigned int argcu = (unsigned int)argc; ascii_encode_request_t r; if (argcu == 1) usage(argv[0]); r.dstate.mmode = XED_MACHINE_MODE_LEGACY_32; r.dstate.stack_addr_width = XED_ADDRESS_WIDTH_32b; for( ; i< argcu; i++) if (strcmp(argv[i],"-16")==0) r.dstate.mmode = XED_MACHINE_MODE_LEGACY_16; else if (strcmp(argv[i],"-32")==0) r.dstate.mmode = XED_MACHINE_MODE_LEGACY_32; else if (strcmp("-64", argv[i]) == 0) { r.dstate.mmode = XED_MACHINE_MODE_LONG_64; } else if (strcmp("-32", argv[i]) == 0) r.dstate.mmode = XED_MACHINE_MODE_LEGACY_32; else if (strcmp("-16", argv[i]) == 0) r.dstate.mmode = XED_MACHINE_MODE_LEGACY_16; else if (strcmp(argv[i],"-s32")==0) r.dstate.stack_addr_width = XED_ADDRESS_WIDTH_32b; else if (strcmp(argv[i],"-s16")==0) r.dstate.stack_addr_width = XED_ADDRESS_WIDTH_16b; else break; if (i == argcu) usage(argv[0]); c = xed_strdup(argv[i++]); for( ;i