Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help for assembly

Status
Not open for further replies.

janakiram.sistla

Member level 1
Member level 1
Joined
Sep 21, 2005
Messages
40
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,286
Activity points
1,745
hi all
pleasse can any body suggest me how to write switch case using assembly may be any syntax
 

you can write switch case in assembly
like ex if u have 5 case statement like beow one.
switch(var)
case 5: statement
case 4:
case 3:
case 2:
case1:

u can write same thing in assembly as

mov

Added after 1 minutes:

you can write switch case in assembly
like ex if u have 5 case statement like beow one.
switch(var)
case 5: statement
case 4:
case 3:
case 2:
case1:

u can write same thing in assembly as

mov a,var
dec a
jz case1
dec a
jz case2
dec a
jz case3
dec a
jz case 4
dec a
jz case5
 

Switch case can be written as below:

mov a,'case'

CJNE 'case1','target'
CJNE 'case2','target'
CJNE 'case3','target'

and so forth. CJNE: Compare and jump if not equal.
 

CJNE? Compare and Jump if Not Equal? I think that's only works if you using that assembly for Uc? I don't think that'll work on Intel 8088 assembly.
Please correct me if i'm wrong :)
Thanks
 

CJNE is an instruction of Microcontroller 8051 family. I'm not sure is it valid in intel 8088 or not. Please check the instruction set. But, this is a way to do the switch case. I think there's instruction doing compare and jump for intel 8088.
 

or:

mov register,variable
cmp register,comparison1
je case1
cmp register,comparison2
je case2
cmp register,comparison3
je case3
cmp register,comparison4
je case4
cmp register,comparison5
je case5
jmp default

but this is more of an if...else if...else approach
 

You need to be a little bit more precise on conditions of the CASE.
For example if its monotonic numbers (0,1,2,3,..,n)
then it can be done by one clock handling
(32 bit address mode)
.data
jmptbl dd case0,case1,...,casen
.code
;assuming case number in eax
jmp jmptbl[eax*4]
case0: ;code for case0
....
jmp endcase
case1: ;code for case1
...
jmp endcase
....
casen: ;....
....

endcase:

if its monitonic but there are cases "else" that are not in the monotonic range then filtering them must precede the above code,
for example the monotinic ragne is from m to n(included) then before the code above you must filter out the cases "else", one of short unbranched ways might be
;assuming case number in eax
sub eax,m
cmp eax,n-m+1
jnc caseelse
jmp jmptbl+m*4[eax*4]
There are other ways depending on type of CASES.
There are no isomorphic relation between ANY HLL programming CASE condition and assembly translation of it. Though most "universal" way covering most of HLL condition design (yet not the fastest) is
cmp eax,CASEone
je @CASEoneHandler
cmp eax,CASEother
je @CASEotherHangler
cmp eax,17
jc @CASElessThen17Handler
@CaseOtherOnes:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top