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;
}
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
|
show 1 more comment
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
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-lastint 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 likejmp $
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
|
show 1 more comment
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
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
assembly x86
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-lastint 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 likejmp $
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
|
show 1 more comment
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-lastint 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 likejmp $
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
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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