source: trunk/minix/commands/i386/asmconv/asm86.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.6 KB
Line 
1/* asm86.c - 80X86 assembly intermediate Author: Kees J. Bot
2 * 24 Dec 1993
3 */
4#define nil 0
5#include <stddef.h>
6#include <string.h>
7#include <assert.h>
8#include "asm86.h"
9#include "asmconv.h"
10#include "token.h"
11
12expression_t *new_expr(void)
13/* Make a new cell to build an expression. */
14{
15 expression_t *e;
16
17 e= allocate(nil, sizeof(*e));
18 e->operator= -1;
19 e->left= e->middle= e->right= nil;
20 e->name= nil;
21 e->magic= 31624;
22 return e;
23}
24
25void del_expr(expression_t *e)
26/* Delete an expression tree. */
27{
28 if (e != nil) {
29 assert(e->magic == 31624);
30 e->magic= 0;
31 deallocate(e->name);
32 del_expr(e->left);
33 del_expr(e->middle);
34 del_expr(e->right);
35 deallocate(e);
36 }
37}
38
39asm86_t *new_asm86(void)
40/* Make a new cell to hold an 80X86 instruction. */
41{
42 asm86_t *a;
43
44 a= allocate(nil, sizeof(*a));
45 a->opcode= -1;
46 get_file(&a->file, &a->line);
47 a->optype= -1;
48 a->oaz= 0;
49 a->rep= ONCE;
50 a->seg= DEFSEG;
51 a->args= nil;
52 a->magic= 37937;
53 return a;
54}
55
56void del_asm86(asm86_t *a)
57/* Delete an 80X86 instruction. */
58{
59 assert(a != nil);
60 assert(a->magic == 37937);
61 a->magic= 0;
62 del_expr(a->args);
63 deallocate(a);
64}
65
66int isregister(const char *name)
67/* True if the string is a register name. Return its size. */
68{
69 static char *regs[] = {
70 "al", "bl", "cl", "dl", "ah", "bh", "ch", "dh",
71 "ax", "bx", "cx", "dx", "si", "di", "bp", "sp",
72 "cs", "ds", "es", "fs", "gs", "ss",
73 "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp",
74 "cr0", "cr1", "cr2", "cr3",
75 "st",
76 };
77 int reg;
78
79 for (reg= 0; reg < arraysize(regs); reg++) {
80 if (strcmp(name, regs[reg]) == 0) {
81 return reg < 8 ? 1 : reg < 22 ? 2 : 4;
82 }
83 }
84 return 0;
85}
Note: See TracBrowser for help on using the repository browser.