Author Topic: How do you do a embedded if in assembly?  (Read 17291 times)

Offline maplesirop

  • Jr. Member
  • *
  • Posts: 60
How do you do a embedded if in assembly?
« on: February 23, 2013, 09:22:05 PM »
Code: [Select]
(...)
cmp ecx, 48
jl warn
cmp ecx, 57
jg warn
inc ecx




warn: cmp ecx, 97
jle stop
cmp ecx, 122
jge stop
mov eax, 4
mov ebx, 1
mov ecx, alert
mov edx, len
int 0x80

warn: (...)




would this work?

Offline Gerhard

  • Jr. Member
  • *
  • Posts: 51
Re: How do you do a embedded if in assembly?
« Reply #1 on: February 23, 2013, 09:35:00 PM »
Hi maplesirop,

would this work?

probably not, because you've the same label (warn) two times in your source.

Gerhard

Offline maplesirop

  • Jr. Member
  • *
  • Posts: 60
Re: How do you do a embedded if in assembly?
« Reply #2 on: February 24, 2013, 12:54:20 AM »
thanks, would it work otherwise?

Offline Gerhard

  • Jr. Member
  • *
  • Posts: 51
Re: How do you do a embedded if in assembly?
« Reply #3 on: February 24, 2013, 01:10:13 AM »
Hi maplesirop,

thanks, would it work otherwise?

that's not so clear. Where is the label stop? What would you like to do? Do you need only the if-tree or the if-else-trees? In any case, that ressource could be of interst for you: http://www.drpaulcarter.com/pcasm/. I hope that helps.

Gerhard

Offline maplesirop

  • Jr. Member
  • *
  • Posts: 60
Re: How do you do a embedded if in assembly?
« Reply #4 on: February 24, 2013, 02:08:57 AM »
Code: [Select]
I need to embbed several if statements

if (x=1)
{
x++
}
else
{
if (x=2)
{
x=0;
}
else
{
if(x=0)
{
x++;
}
}
}

Offline Gerhard

  • Jr. Member
  • *
  • Posts: 51
Re: How do you do a embedded if in assembly?
« Reply #5 on: February 24, 2013, 02:53:19 AM »
Hi maplesirop,

that looks like a case select:

Code: [Select]
  case 0:
    x++
  case 1:
    x++
  case 2:
    x=0

Is that your goal?

Gerhard

Offline maplesirop

  • Jr. Member
  • *
  • Posts: 60
Re: How do you do a embedded if in assembly?
« Reply #6 on: February 24, 2013, 02:56:43 AM »
Hi maplesirop,

that looks like a case select:

Code: [Select]
  case 0:
    x++
  case 1:
    x++
  case 2:
    x=0

Is that your goal?

Gerhard

yes

can you help me with my segmentation fault problem?

Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
Re: How do you do a embedded if in assembly?
« Reply #7 on: February 24, 2013, 12:23:36 PM »
Code: [Select]
if (x=1)
{
x++
}
else
{
if (x=2)
{
x=0;
}
else
{
if(x=0)
{
x++;
}
}
}


can be translated to.

Code: [Select]
cmp ecx,1
jne elselabel1
inc ecx
jmp endiflabel1
elselabel1:
  cmp ecx, 2
jne elselabel2
mov ecx,2
jmp endiflabel2
elselabel2:
cmp ecx, 0
jne endiflabel3     ;;jump to endif directly
inc ecx
endiflabel3:
endiflabel2:
endiflabel1:

I would suggest to follow a label naming convention like this when you code a nested if-else constructs.

Try it and let us know.

Offline maplesirop

  • Jr. Member
  • *
  • Posts: 60
Re: How do you do a embedded if in assembly?
« Reply #8 on: February 25, 2013, 04:40:53 AM »
thanks