Skip to main content

Posts

Showing posts with the label assembly language if statement tutorial programming stack frame condition testing cmp instruction c printf

Writing if statements in assembly language

Programs become more and more interesting when you have dynamic elements in them.  On such way of bringing your program to life is by adding logic.  In assembly, the task can seem dubious and awkward, but once you get a grip on the concept, it will be but second nature. So lets get started! //We want to write an equivalent program to this in assembly #include <stdio.h> int main(){ int x = 40; if( x > 10){ printf("x is greater than 10\n"); }else{ printf("x is lesser than 10\n"); } return 0; } To write this in assembly, consider the following: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "x is greater than 10", 10, 0 msg2: db "x is lesser than 10", 10, 0 SECTION .text Here, all we did is create our variable x, and the respective message that we will display depending on the result of our if statement. Continually: ;an equivalent program to this in assembly SECTION .data x: dd 40 msg1: db "