flat assembler
Message board for the users of flat assembler.

Index > Main > Assembler i8086

Author
Thread Post new topic Reply to topic
MariaSM



Joined: 03 May 2014
Posts: 41
MariaSM
I need some help...I want to know how can I write something like this: 4*a+a/6-7 in assembler I8086. Thanks a lot!
Smile
I need only that part of program.not all the program
Post 25 Aug 2014, 14:02
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I assume (from i8086) that your variable 'a' is a 16-bit integer value.
Then you need to do the following:

1. load 'a' (with MOV instruction) and multiply it by 4 (use IMUL, MUL or SHL)
2. load 'a' and divide it by 6 (use IDIV or DIV)
3. add (use ADD) results from steps #1 and #2 and subtract 7 from that sum (use SUB)

All your instructions are here:
http://www.electronics.dit.ie/staff/tscarff/8086_instruction_set/8086_instruction_set.html
Post 25 Aug 2014, 18:03
View user's profile Send private message Send e-mail Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 724
tthsqe
Code:
f:
mov ax,[sp+2]
mov cx,ax
shl  cx,2
xor  dx,dx
idiv  ax,6
add  cx,-7
add  ax,cx
ret 2


; to call f(2)
push 2
call f
; f(2) result now in ax      
Post 25 Aug 2014, 19:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.