Assembly x86 check if 3 values can form a triangle





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have to do this problem where I have the sides and I have to check if they can form a triangle. Now I have this code but I don't know why I get both of the messages.I am new to the assembly language.



.model small
.stack 128
.data
a dw 1
b dw 20
c dw 3
msg1 db 'The sides can form a triangle$'
msg2 db 'The sides cannot form a triangle$'

.code
mov AX, @data
mov DS, AX

MOV AX,a
add AX,b
mov bX,b
add bX,c
mov cX,a
add cX,c

CMP AX,c
JAE L1
mov dx, offset msg2
mov ah,9
int 21h

L1:
CMP bX,a
JAE L2
mov dx, offset msg2
mov ah,9
int 21h

L2:
CMP cX,b
JAE L3
mov dx, offset msg2
mov ah,9
int 21h

L3:
mov dx,offset msg1
mov ah,9
int 21h
end









share|improve this question


















  • 3





    Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

    – Some programmer dude
    Jan 3 at 10:39






  • 1





    Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

    – Peter Cordes
    Jan 3 at 10:50











  • Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

    – Alexstuica120
    Jan 3 at 11:36






  • 1





    @Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

    – Ped7g
    Jan 3 at 11:52













  • In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

    – Ped7g
    Jan 3 at 11:57


















2















I have to do this problem where I have the sides and I have to check if they can form a triangle. Now I have this code but I don't know why I get both of the messages.I am new to the assembly language.



.model small
.stack 128
.data
a dw 1
b dw 20
c dw 3
msg1 db 'The sides can form a triangle$'
msg2 db 'The sides cannot form a triangle$'

.code
mov AX, @data
mov DS, AX

MOV AX,a
add AX,b
mov bX,b
add bX,c
mov cX,a
add cX,c

CMP AX,c
JAE L1
mov dx, offset msg2
mov ah,9
int 21h

L1:
CMP bX,a
JAE L2
mov dx, offset msg2
mov ah,9
int 21h

L2:
CMP cX,b
JAE L3
mov dx, offset msg2
mov ah,9
int 21h

L3:
mov dx,offset msg1
mov ah,9
int 21h
end









share|improve this question


















  • 3





    Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

    – Some programmer dude
    Jan 3 at 10:39






  • 1





    Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

    – Peter Cordes
    Jan 3 at 10:50











  • Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

    – Alexstuica120
    Jan 3 at 11:36






  • 1





    @Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

    – Ped7g
    Jan 3 at 11:52













  • In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

    – Ped7g
    Jan 3 at 11:57














2












2








2








I have to do this problem where I have the sides and I have to check if they can form a triangle. Now I have this code but I don't know why I get both of the messages.I am new to the assembly language.



.model small
.stack 128
.data
a dw 1
b dw 20
c dw 3
msg1 db 'The sides can form a triangle$'
msg2 db 'The sides cannot form a triangle$'

.code
mov AX, @data
mov DS, AX

MOV AX,a
add AX,b
mov bX,b
add bX,c
mov cX,a
add cX,c

CMP AX,c
JAE L1
mov dx, offset msg2
mov ah,9
int 21h

L1:
CMP bX,a
JAE L2
mov dx, offset msg2
mov ah,9
int 21h

L2:
CMP cX,b
JAE L3
mov dx, offset msg2
mov ah,9
int 21h

L3:
mov dx,offset msg1
mov ah,9
int 21h
end









share|improve this question














I have to do this problem where I have the sides and I have to check if they can form a triangle. Now I have this code but I don't know why I get both of the messages.I am new to the assembly language.



.model small
.stack 128
.data
a dw 1
b dw 20
c dw 3
msg1 db 'The sides can form a triangle$'
msg2 db 'The sides cannot form a triangle$'

.code
mov AX, @data
mov DS, AX

MOV AX,a
add AX,b
mov bX,b
add bX,c
mov cX,a
add cX,c

CMP AX,c
JAE L1
mov dx, offset msg2
mov ah,9
int 21h

L1:
CMP bX,a
JAE L2
mov dx, offset msg2
mov ah,9
int 21h

L2:
CMP cX,b
JAE L3
mov dx, offset msg2
mov ah,9
int 21h

L3:
mov dx,offset msg1
mov ah,9
int 21h
end






assembly x86






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 10:33









Alexstuica120Alexstuica120

175




175








  • 3





    Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

    – Some programmer dude
    Jan 3 at 10:39






  • 1





    Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

    – Peter Cordes
    Jan 3 at 10:50











  • Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

    – Alexstuica120
    Jan 3 at 11:36






  • 1





    @Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

    – Ped7g
    Jan 3 at 11:52













  • In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

    – Ped7g
    Jan 3 at 11:57














  • 3





    Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

    – Some programmer dude
    Jan 3 at 10:39






  • 1





    Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

    – Peter Cordes
    Jan 3 at 10:50











  • Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

    – Alexstuica120
    Jan 3 at 11:36






  • 1





    @Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

    – Ped7g
    Jan 3 at 11:52













  • In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

    – Ped7g
    Jan 3 at 11:57








3




3





Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

– Some programmer dude
Jan 3 at 10:39





Knowing how to use a debugger is a crucial skill for any programmer. For assembly programmers doubly so IMO. Use an assembly-level debugger to step through the code operation by operation, while keeping an eye on the registers, to learn when and where it goes wrong.

– Some programmer dude
Jan 3 at 10:39




1




1





Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

– Peter Cordes
Jan 3 at 10:50





Execution falls through labels. If execution reaches the 2nd-last int 21h, it unavoidably falls through into L3.

– Peter Cordes
Jan 3 at 10:50













Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

– Alexstuica120
Jan 3 at 11:36





Thank you! I fixed that. I have one more question. Can I jump a label or jump directly to end?

– Alexstuica120
Jan 3 at 11:36




1




1





@Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

– Ped7g
Jan 3 at 11:52







@Alexstuica120 there is no "end", the CPU doesn't stop, until you power-off the computer. There is always next instruction to execute. In DOS environment you can either call ah=4Ch DOS service (terminate) and let DOS to deal with the powered CPU (generally good idea), or you can create infinite loop like jmp $ burning CPU power yourself (often used by experimental bootloaders to stop execution after certain point... as there is no DOS service to call in bootloader). (you can of course jump to any memory address any time you wish)

– Ped7g
Jan 3 at 11:52















In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

– Ped7g
Jan 3 at 11:57





In case you let CPU reach the point of your code at "end" and you didn't define next instruction, then the CPU will continue executing at that point, whatever is in memory stored there (probably some random stuff), i.e. most likely crashing your system. So you should always "terminate" your code when you reach "end", yourself. Either by using OS service, or by looping infinitely if you are without OS. The "end" in the source is just directive for assembler to stop assembling, but is not part of the code as something meaningful for CPU, CPU doesn't care about your source, it sees only op-codes.

– Ped7g
Jan 3 at 11:57












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020522%2fassembly-x86-check-if-3-values-can-form-a-triangle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020522%2fassembly-x86-check-if-3-values-can-form-a-triangle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith