Advertise

Monday, 16 September 2013

Assembly Language Primer For Hackers (Part 9) Conditional Branching



Description: This is Part 9 of the "Assembly Language Primer for Hackers" video series. Please start here by watching Part 1 of this series, if you have not already done so. In this video we will look at Conditional Branching in Assembly Language using the JXX family of instructions and the LOOP instruction. The conditional jump instructions such as JA, JAE, JZ, JNZ etc. use various flags in the EFLAGS register such as the Zero Flag (ZF), the Parity Flag (PF), Overflow Flag (OF), Sign Flag (SF) etc. to determine which instruction path to take next. In this video we will look at the JZ condition jump instruction in great detail. JZ using the Zero Flag (ZF) to determine if the last instruction resulted in the Zero operation or not and then chooses to jump to a specified location if it was set. We will also look at the LOOP instruction which used the ECX register to loop over a set of instructions over and over again. Please download the ConditionalBranching.s sample code file to try the example shown in this video. 

Code:
.data
 
    HelloWorld:
        .asciz "Hello World!\n"

    ZeroFlagSet:
        .asciz    "Zero Flag was Set!"

    ZeroFlagNotSet:
        .asciz  "Zero Flag Not Set!"


.text

    .globl _start

    _start:

        nop 
        movl $10, %eax
        xorl %eax, %eax
        jz PrintHelloWorld

    FlagNotSetPrint:
        movl $4, %eax
        movl $1, %ebx
        leal ZeroFlagNotSet, %ecx
        movl $19, %edx
        int $0x80
        jmp ExitCall



    FlagSetPrint:
        movl $4, %eax
        movl $1, %ebx
        leal ZeroFlagSet, %ecx
        movl $19, %edx
        int $0x80
        jmp ExitCall


    ExitCall:
        movl $1, %eax
        movl $0, %ebx
        int $0x80

    PrintHelloWorld:
        movl $10, %ecx
        PrintTenTimes:
            pushl %ecx
            movl $4, %eax
            movl $1, %ebx
            leal HelloWorld, %ecx
            movl $14, %edx
            int $0x80
            popl %ecx
        loop PrintTenTimes
        jmp ExitCall

Disclaimer: We are a infosec video aggregator and this video is linked from an external website. The original author may be different from the user re-posting/linking it here. Please do not assume the authors to be same without verifying. 

Security tube is also providing linux Assembly course for 99$ here -> http://securitytube-training.com/online-...ly-expert/
 
World of Hacker © 2011 Creative Commons License
World of Hacker by KroKite is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at http://www.worldofhacker.com.
Permissions beyond the scope of this license may be available at https://groups.google.com/forum/#!newtopic/hackerforum.