Swap Columns of Display 8086 Assembly





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







0















Everyone.



I want to flip the columns of the video screen/d/display in 8086 DOS emulator process. I am studying assembly language in school.



The question is swap the right vertical half of the screen with the left half of the vertical screen.



I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on. I am having difficulty calculating the exact screen location. Also, I need two counters to store the value of the first and last column which will be incremented and decremented respectively. Also, I need two registers to swap the column values. There should be no clrscr function.



Here is my attempted code:



<pre>`
[org 0x0100]


mov bx,1 ;dummy number
mov di,1 ;left-most column


Call FlipColumn

FlipColumn:


mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di],ax ;first row & first column element
mov dx,[es:di]

FlipColumn1:

mov di, 25
mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di], dx

jne FlipColumn
ret

mov ax,0x4c00
int 21h

</pre>`


In this code, there are addressing issues and I can't configure how to swap those two columns. Please let me know if there is a different way to swap those memory locations.



Thanks.



Okay, friends, I modified this code like this:



<pre>`
[org 0x0100]

mov di, 1
mov si, 41

FlipColumn:

mov ax, 0xb800
mov es, ax

mov word ax, [es:1*80+1]
mov word bx, [es:41*80+1]
mov word [es:1*80+1], bx
mov word [es:41*80+1], ax

inc si
inc di
cmp si, 80
jbe FlipColumn
mov ax, 0x4c00
int 21h`
</pre>


I wanted to use this statement:



       mov ax, [es:di*80+1]
mov bx, [es:si*80+1]


But the debugger says, it is an addressing error. Any idea how can I increment and decrement the si and di so that I can swap the right and left sides of the display.










share|improve this question

























  • Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

    – Ped7g
    Nov 22 '18 at 15:14











  • and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

    – Ped7g
    Nov 22 '18 at 15:16













  • Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

    – Tanzeel
    Nov 22 '18 at 17:02











  • I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

    – Tanzeel
    Nov 22 '18 at 17:17


















0















Everyone.



I want to flip the columns of the video screen/d/display in 8086 DOS emulator process. I am studying assembly language in school.



The question is swap the right vertical half of the screen with the left half of the vertical screen.



I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on. I am having difficulty calculating the exact screen location. Also, I need two counters to store the value of the first and last column which will be incremented and decremented respectively. Also, I need two registers to swap the column values. There should be no clrscr function.



Here is my attempted code:



<pre>`
[org 0x0100]


mov bx,1 ;dummy number
mov di,1 ;left-most column


Call FlipColumn

FlipColumn:


mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di],ax ;first row & first column element
mov dx,[es:di]

FlipColumn1:

mov di, 25
mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di], dx

jne FlipColumn
ret

mov ax,0x4c00
int 21h

</pre>`


In this code, there are addressing issues and I can't configure how to swap those two columns. Please let me know if there is a different way to swap those memory locations.



Thanks.



Okay, friends, I modified this code like this:



<pre>`
[org 0x0100]

mov di, 1
mov si, 41

FlipColumn:

mov ax, 0xb800
mov es, ax

mov word ax, [es:1*80+1]
mov word bx, [es:41*80+1]
mov word [es:1*80+1], bx
mov word [es:41*80+1], ax

inc si
inc di
cmp si, 80
jbe FlipColumn
mov ax, 0x4c00
int 21h`
</pre>


I wanted to use this statement:



       mov ax, [es:di*80+1]
mov bx, [es:si*80+1]


But the debugger says, it is an addressing error. Any idea how can I increment and decrement the si and di so that I can swap the right and left sides of the display.










share|improve this question

























  • Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

    – Ped7g
    Nov 22 '18 at 15:14











  • and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

    – Ped7g
    Nov 22 '18 at 15:16













  • Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

    – Tanzeel
    Nov 22 '18 at 17:02











  • I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

    – Tanzeel
    Nov 22 '18 at 17:17














0












0








0








Everyone.



I want to flip the columns of the video screen/d/display in 8086 DOS emulator process. I am studying assembly language in school.



The question is swap the right vertical half of the screen with the left half of the vertical screen.



I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on. I am having difficulty calculating the exact screen location. Also, I need two counters to store the value of the first and last column which will be incremented and decremented respectively. Also, I need two registers to swap the column values. There should be no clrscr function.



Here is my attempted code:



<pre>`
[org 0x0100]


mov bx,1 ;dummy number
mov di,1 ;left-most column


Call FlipColumn

FlipColumn:


mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di],ax ;first row & first column element
mov dx,[es:di]

FlipColumn1:

mov di, 25
mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di], dx

jne FlipColumn
ret

mov ax,0x4c00
int 21h

</pre>`


In this code, there are addressing issues and I can't configure how to swap those two columns. Please let me know if there is a different way to swap those memory locations.



Thanks.



Okay, friends, I modified this code like this:



<pre>`
[org 0x0100]

mov di, 1
mov si, 41

FlipColumn:

mov ax, 0xb800
mov es, ax

mov word ax, [es:1*80+1]
mov word bx, [es:41*80+1]
mov word [es:1*80+1], bx
mov word [es:41*80+1], ax

inc si
inc di
cmp si, 80
jbe FlipColumn
mov ax, 0x4c00
int 21h`
</pre>


I wanted to use this statement:



       mov ax, [es:di*80+1]
mov bx, [es:si*80+1]


But the debugger says, it is an addressing error. Any idea how can I increment and decrement the si and di so that I can swap the right and left sides of the display.










share|improve this question
















Everyone.



I want to flip the columns of the video screen/d/display in 8086 DOS emulator process. I am studying assembly language in school.



The question is swap the right vertical half of the screen with the left half of the vertical screen.



I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on. I am having difficulty calculating the exact screen location. Also, I need two counters to store the value of the first and last column which will be incremented and decremented respectively. Also, I need two registers to swap the column values. There should be no clrscr function.



Here is my attempted code:



<pre>`
[org 0x0100]


mov bx,1 ;dummy number
mov di,1 ;left-most column


Call FlipColumn

FlipColumn:


mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di],ax ;first row & first column element
mov dx,[es:di]

FlipColumn1:

mov di, 25
mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mull byte [di] ; multiply with y position
add ax, [bx] ; add x position
shl ax, 1 ; turn into byte offset
mov di, ax ; point di to required location

mov [es:di], dx

jne FlipColumn
ret

mov ax,0x4c00
int 21h

</pre>`


In this code, there are addressing issues and I can't configure how to swap those two columns. Please let me know if there is a different way to swap those memory locations.



Thanks.



Okay, friends, I modified this code like this:



<pre>`
[org 0x0100]

mov di, 1
mov si, 41

FlipColumn:

mov ax, 0xb800
mov es, ax

mov word ax, [es:1*80+1]
mov word bx, [es:41*80+1]
mov word [es:1*80+1], bx
mov word [es:41*80+1], ax

inc si
inc di
cmp si, 80
jbe FlipColumn
mov ax, 0x4c00
int 21h`
</pre>


I wanted to use this statement:



       mov ax, [es:di*80+1]
mov bx, [es:si*80+1]


But the debugger says, it is an addressing error. Any idea how can I increment and decrement the si and di so that I can swap the right and left sides of the display.







assembly nasm x86-16 emu8086






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 17:12







Tanzeel

















asked Nov 22 '18 at 14:08









Tanzeel Tanzeel

11




11













  • Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

    – Ped7g
    Nov 22 '18 at 15:14











  • and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

    – Ped7g
    Nov 22 '18 at 15:16













  • Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

    – Tanzeel
    Nov 22 '18 at 17:02











  • I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

    – Tanzeel
    Nov 22 '18 at 17:17



















  • Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

    – Ped7g
    Nov 22 '18 at 15:14











  • and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

    – Ped7g
    Nov 22 '18 at 15:16













  • Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

    – Tanzeel
    Nov 22 '18 at 17:02











  • I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

    – Tanzeel
    Nov 22 '18 at 17:17

















Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

– Ped7g
Nov 22 '18 at 15:14





Common text mode on PC is 80x25, i.e. has 80 columns, not 25. And you want "swap left half with right half", but then "pick first column and exchange with last", and then "2nd column exchange with 24th" .. all of these are contradicting each other. If you want swap left and right half (vertical halves), you swap 1st column with 41th, 2nd with 42nd, ... and 40th with 80th column. If you want swap first vs last and then proceed toward centre, that's "mirror X" (but without mirroring character graphics itself, just chars). If you want to put screen "upside down", that's "mirror Y", etc...

– Ped7g
Nov 22 '18 at 15:14













and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

– Ped7g
Nov 22 '18 at 15:16







and when programming in assembly, you have to be very precise, so sort first what you actually want to do, and then edit your question... maybe you will be able also to partly fix your code, once you will be able more clearly articulate, what you want to achieve. (btw the amount of bugs or misconceptions in your current code is about one misconception per every three lines or so (no swap happening for example), so don't hesitate to even throw it out several times and start over and over. Unless you are size/performance limited (you are NOT), assembly source can/should read quite clearly too.

– Ped7g
Nov 22 '18 at 15:16















Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

– Tanzeel
Nov 22 '18 at 17:02





Thank you so much for your reply. I have modified my code but the output is not what I would like to get.

– Tanzeel
Nov 22 '18 at 17:02













I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

– Tanzeel
Nov 22 '18 at 17:17





I tried hard-coding but the output is not what I want. Maybe I am not clarifying my question. I need to flip the video screen of the emulator from left to right.

– Tanzeel
Nov 22 '18 at 17:17












2 Answers
2






active

oldest

votes


















2














Here is an example of how to mirror. Fundamentally the two algorithms are the same but as @Ped7g pointed out, the specification is not really definitive.




I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on




            push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 158
mov cx, 25

L0: push cx
mov cx, 40
push di
push si

L1: mov ax, [di]
mov bx, [si]
mov [di], bx
mov [si], ax
inc si
inc si
dec di
dec di
loop L1

pop si
pop di
add si, 160
add di, 160

pop cx
loop L0

pop es
pop ds





share|improve this answer





















  • 2





    you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

    – Ped7g
    Nov 23 '18 at 22:22











  • Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

    – Sep Roland
    Nov 25 '18 at 20:16











  • Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

    – Sep Roland
    Nov 25 '18 at 20:18











  • @SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

    – Shift_Left
    Nov 25 '18 at 21:49



















1














Normally I wouldn't respond in this fashion as far too often all it equates to is doing the assignment for you, but you have put in a reasonable amount of effort so I'm going to give this example as it is a lot simpler than trying to explain why your methodology doesn't work. I've purposely left out comments as it will be incumbent upon you to use your emulator's debugger to understand the code and comment it before handing it in.



    push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 80
mov cx, 25

L0: push cx
mov cx, 40

L1: mov ax, [di]
movsw
mov [si-2], ax
loop L1

xchg si, di
add di, 160
pop cx
loop L0

pop es
pop ds


There is probably going to be a couple of improvisations you're going to need to make to this NASM code, but I'm sure you'll figure it out.






share|improve this answer
























  • Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

    – Ped7g
    Nov 23 '18 at 10:02











  • @Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

    – Shift_Left
    Nov 23 '18 at 13:01












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%2f53432772%2fswap-columns-of-display-8086-assembly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Here is an example of how to mirror. Fundamentally the two algorithms are the same but as @Ped7g pointed out, the specification is not really definitive.




I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on




            push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 158
mov cx, 25

L0: push cx
mov cx, 40
push di
push si

L1: mov ax, [di]
mov bx, [si]
mov [di], bx
mov [si], ax
inc si
inc si
dec di
dec di
loop L1

pop si
pop di
add si, 160
add di, 160

pop cx
loop L0

pop es
pop ds





share|improve this answer





















  • 2





    you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

    – Ped7g
    Nov 23 '18 at 22:22











  • Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

    – Sep Roland
    Nov 25 '18 at 20:16











  • Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

    – Sep Roland
    Nov 25 '18 at 20:18











  • @SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

    – Shift_Left
    Nov 25 '18 at 21:49
















2














Here is an example of how to mirror. Fundamentally the two algorithms are the same but as @Ped7g pointed out, the specification is not really definitive.




I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on




            push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 158
mov cx, 25

L0: push cx
mov cx, 40
push di
push si

L1: mov ax, [di]
mov bx, [si]
mov [di], bx
mov [si], ax
inc si
inc si
dec di
dec di
loop L1

pop si
pop di
add si, 160
add di, 160

pop cx
loop L0

pop es
pop ds





share|improve this answer





















  • 2





    you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

    – Ped7g
    Nov 23 '18 at 22:22











  • Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

    – Sep Roland
    Nov 25 '18 at 20:16











  • Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

    – Sep Roland
    Nov 25 '18 at 20:18











  • @SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

    – Shift_Left
    Nov 25 '18 at 21:49














2












2








2







Here is an example of how to mirror. Fundamentally the two algorithms are the same but as @Ped7g pointed out, the specification is not really definitive.




I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on




            push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 158
mov cx, 25

L0: push cx
mov cx, 40
push di
push si

L1: mov ax, [di]
mov bx, [si]
mov [di], bx
mov [si], ax
inc si
inc si
dec di
dec di
loop L1

pop si
pop di
add si, 160
add di, 160

pop cx
loop L0

pop es
pop ds





share|improve this answer















Here is an example of how to mirror. Fundamentally the two algorithms are the same but as @Ped7g pointed out, the specification is not really definitive.




I want to pick the first column, replace it with the last one. Then pick the 2nd column, replace it with the 24th column and so on




            push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 158
mov cx, 25

L0: push cx
mov cx, 40
push di
push si

L1: mov ax, [di]
mov bx, [si]
mov [di], bx
mov [si], ax
inc si
inc si
dec di
dec di
loop L1

pop si
pop di
add si, 160
add di, 160

pop cx
loop L0

pop es
pop ds






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 21:51

























answered Nov 23 '18 at 13:31









Shift_LeftShift_Left

902417




902417








  • 2





    you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

    – Ped7g
    Nov 23 '18 at 22:22











  • Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

    – Sep Roland
    Nov 25 '18 at 20:16











  • Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

    – Sep Roland
    Nov 25 '18 at 20:18











  • @SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

    – Shift_Left
    Nov 25 '18 at 21:49














  • 2





    you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

    – Ped7g
    Nov 23 '18 at 22:22











  • Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

    – Sep Roland
    Nov 25 '18 at 20:16











  • Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

    – Sep Roland
    Nov 25 '18 at 20:18











  • @SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

    – Shift_Left
    Nov 25 '18 at 21:49








2




2





you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

– Ped7g
Nov 23 '18 at 22:22





you can remove all es related instructions, because this variant doesn't use es anywhere (contrary to the "string" instructions like movsw, which does use es implicitly). Setting up ds for this variant is enough.

– Ped7g
Nov 23 '18 at 22:22













Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

– Sep Roland
Nov 25 '18 at 20:16





Any particular reason for not swapping the 2 middle columns? Because that's what you get with a counter of 39. mov cx, 39

– Sep Roland
Nov 25 '18 at 20:16













Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

– Sep Roland
Nov 25 '18 at 20:18





Although this code is very sub-optimal, I think it's perfect for the limited understanding of the OP. So +1 to you.

– Sep Roland
Nov 25 '18 at 20:18













@SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

– Shift_Left
Nov 25 '18 at 21:49





@SepRoland I did catch that in debug, but neglected to change it in the source before posting. It stood right out in my example using DIR as it turns out the year is right in the middle so, 2015 yielded 5012 and should have been 1502

– Shift_Left
Nov 25 '18 at 21:49













1














Normally I wouldn't respond in this fashion as far too often all it equates to is doing the assignment for you, but you have put in a reasonable amount of effort so I'm going to give this example as it is a lot simpler than trying to explain why your methodology doesn't work. I've purposely left out comments as it will be incumbent upon you to use your emulator's debugger to understand the code and comment it before handing it in.



    push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 80
mov cx, 25

L0: push cx
mov cx, 40

L1: mov ax, [di]
movsw
mov [si-2], ax
loop L1

xchg si, di
add di, 160
pop cx
loop L0

pop es
pop ds


There is probably going to be a couple of improvisations you're going to need to make to this NASM code, but I'm sure you'll figure it out.






share|improve this answer
























  • Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

    – Ped7g
    Nov 23 '18 at 10:02











  • @Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

    – Shift_Left
    Nov 23 '18 at 13:01
















1














Normally I wouldn't respond in this fashion as far too often all it equates to is doing the assignment for you, but you have put in a reasonable amount of effort so I'm going to give this example as it is a lot simpler than trying to explain why your methodology doesn't work. I've purposely left out comments as it will be incumbent upon you to use your emulator's debugger to understand the code and comment it before handing it in.



    push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 80
mov cx, 25

L0: push cx
mov cx, 40

L1: mov ax, [di]
movsw
mov [si-2], ax
loop L1

xchg si, di
add di, 160
pop cx
loop L0

pop es
pop ds


There is probably going to be a couple of improvisations you're going to need to make to this NASM code, but I'm sure you'll figure it out.






share|improve this answer
























  • Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

    – Ped7g
    Nov 23 '18 at 10:02











  • @Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

    – Shift_Left
    Nov 23 '18 at 13:01














1












1








1







Normally I wouldn't respond in this fashion as far too often all it equates to is doing the assignment for you, but you have put in a reasonable amount of effort so I'm going to give this example as it is a lot simpler than trying to explain why your methodology doesn't work. I've purposely left out comments as it will be incumbent upon you to use your emulator's debugger to understand the code and comment it before handing it in.



    push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 80
mov cx, 25

L0: push cx
mov cx, 40

L1: mov ax, [di]
movsw
mov [si-2], ax
loop L1

xchg si, di
add di, 160
pop cx
loop L0

pop es
pop ds


There is probably going to be a couple of improvisations you're going to need to make to this NASM code, but I'm sure you'll figure it out.






share|improve this answer













Normally I wouldn't respond in this fashion as far too often all it equates to is doing the assignment for you, but you have put in a reasonable amount of effort so I'm going to give this example as it is a lot simpler than trying to explain why your methodology doesn't work. I've purposely left out comments as it will be incumbent upon you to use your emulator's debugger to understand the code and comment it before handing it in.



    push    ds
push es
mov ax, 0xb800
mov ds, ax
mov es, ax
xor si, si
mov di, 80
mov cx, 25

L0: push cx
mov cx, 40

L1: mov ax, [di]
movsw
mov [si-2], ax
loop L1

xchg si, di
add di, 160
pop cx
loop L0

pop es
pop ds


There is probably going to be a couple of improvisations you're going to need to make to this NASM code, but I'm sure you'll figure it out.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 23:53









Shift_LeftShift_Left

902417




902417













  • Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

    – Ped7g
    Nov 23 '18 at 10:02











  • @Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

    – Shift_Left
    Nov 23 '18 at 13:01



















  • Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

    – Ped7g
    Nov 23 '18 at 10:02











  • @Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

    – Shift_Left
    Nov 23 '18 at 13:01

















Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

– Ped7g
Nov 23 '18 at 10:02





Did you debug it yourself, or try it? I don't believe it's doing "mirror x", it's swapping the left with right half of screens (by reading the source, didn't try it myself)... which is probably ok for OP to see how imprecise wording can lead to completely different result than expected. But the swap with movsw included is making it just more confusing for the mirror way, where the basic mov sequence makes more sense. :)

– Ped7g
Nov 23 '18 at 10:02













@Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

– Shift_Left
Nov 23 '18 at 13:01





@Ped7g Yes I did assemble to a .COM and tested it in DosBox. I chose to flip a coin and go with paragraph two, but paragraph three contradicts it though largely due to swapping col 0 with 79 and then 1 with 23 didn't make a lot of sense. Ultimately I thought, if OP sees how a nested loop would be implemented, that might be a step in the right direction.

– Shift_Left
Nov 23 '18 at 13:01


















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%2f53432772%2fswap-columns-of-display-8086-assembly%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

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?