English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How do I translate these codes to assembly language?

x = a + 19 - b

z = a * a * a (a = 2 bytes)

Can anyone also tell me where I can read more on this subject?

2007-02-21 10:49:13 · 4 answers · asked by Rosy 3 in Computers & Internet Programming & Design

4 answers

Assuming x86 assembler, try-
LD AX, [address of a]
LD BX, [address of b]
ADD AX, 19d // Decimal
SUB AX, BX
LD [address of x], AX

LD AX, [address of a]
LD BX, AX
IMUL BX // 4 byte result saved in dx:ax
PUSH AX
MOVZ EAX, DX // now top of eax holds dx
POP AX // now eax = dx:ax
IMUL BX
// 6 byte result in EDX:EAX

2007-02-21 11:40:03 · answer #1 · answered by Alan 6 · 0 0

well...if i was on a linux box (or any unix box practically) I'd take the easy way and let the compiler do it for me.

So first I'd make a file blah.c:

void eek() {
short x = 0;
short a = 0;
short b = 0;
short z = 0;

x = a + 19 -b;
z = a * a * a;
}

then I'd compile:

gcc -S -c blah.c

If the syntax is correct, you should see a "blah.s" file with some assembly language in it BUT I realize that this isn't what you are really looking for.

Assembly language is processor specific so you probably need to repost the question with more details. Are the variable global or local. "a" is 2 bytes but what about the rest of the vars, etc..

2007-02-21 11:25:00 · answer #2 · answered by bytekhan 2 · 0 0

With the multitude of higher-level languages out there, why would you want to deal with assembly language?

2007-02-21 10:52:23 · answer #3 · answered by BDZot 6 · 0 1

Which assembly language?

http://en.wikipedia.org/wiki/Assembly_language

http://en.wikipedia.org/wiki/List_of_assemblers

2007-02-21 10:51:56 · answer #4 · answered by Anonymous · 0 1

fedest.com, questions and answers