Swap Columns of Display 8086 Assembly
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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 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 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 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 at 17:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
assembly nasm x86-16 emu8086
edited Nov 22 at 17:12
asked Nov 22 at 14:08
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 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 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 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 at 17:17
add a comment |
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 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 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 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 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 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 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 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 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 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 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 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 at 17:17
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
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
2
you can remove alles
related instructions, because this variant doesn't usees
anywhere (contrary to the "string" instructions likemovsw
, which does usees
implicitly). Setting upds
for this variant is enough.
– Ped7g
Nov 23 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 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 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 usingDIR
as it turns out the year is right in the middle so,2015
yielded5012
and should have been1502
– Shift_Left
Nov 25 at 21:49
add a comment |
up vote
1
down vote
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.
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 withmovsw
included is making it just more confusing for the mirror way, where the basicmov
sequence makes more sense. :)
– Ped7g
Nov 23 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 at 13:01
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
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
2
you can remove alles
related instructions, because this variant doesn't usees
anywhere (contrary to the "string" instructions likemovsw
, which does usees
implicitly). Setting upds
for this variant is enough.
– Ped7g
Nov 23 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 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 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 usingDIR
as it turns out the year is right in the middle so,2015
yielded5012
and should have been1502
– Shift_Left
Nov 25 at 21:49
add a comment |
up vote
2
down vote
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
2
you can remove alles
related instructions, because this variant doesn't usees
anywhere (contrary to the "string" instructions likemovsw
, which does usees
implicitly). Setting upds
for this variant is enough.
– Ped7g
Nov 23 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 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 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 usingDIR
as it turns out the year is right in the middle so,2015
yielded5012
and should have been1502
– Shift_Left
Nov 25 at 21:49
add a comment |
up vote
2
down vote
up vote
2
down vote
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
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
edited Nov 25 at 21:51
answered Nov 23 at 13:31
Shift_Left
894417
894417
2
you can remove alles
related instructions, because this variant doesn't usees
anywhere (contrary to the "string" instructions likemovsw
, which does usees
implicitly). Setting upds
for this variant is enough.
– Ped7g
Nov 23 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 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 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 usingDIR
as it turns out the year is right in the middle so,2015
yielded5012
and should have been1502
– Shift_Left
Nov 25 at 21:49
add a comment |
2
you can remove alles
related instructions, because this variant doesn't usees
anywhere (contrary to the "string" instructions likemovsw
, which does usees
implicitly). Setting upds
for this variant is enough.
– Ped7g
Nov 23 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 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 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 usingDIR
as it turns out the year is right in the middle so,2015
yielded5012
and should have been1502
– Shift_Left
Nov 25 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 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 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 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 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 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 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 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 at 21:49
add a comment |
up vote
1
down vote
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.
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 withmovsw
included is making it just more confusing for the mirror way, where the basicmov
sequence makes more sense. :)
– Ped7g
Nov 23 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 at 13:01
add a comment |
up vote
1
down vote
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.
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 withmovsw
included is making it just more confusing for the mirror way, where the basicmov
sequence makes more sense. :)
– Ped7g
Nov 23 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 at 13:01
add a comment |
up vote
1
down vote
up vote
1
down vote
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.
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.
answered Nov 22 at 23:53
Shift_Left
894417
894417
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 withmovsw
included is making it just more confusing for the mirror way, where the basicmov
sequence makes more sense. :)
– Ped7g
Nov 23 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 at 13:01
add a comment |
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 withmovsw
included is making it just more confusing for the mirror way, where the basicmov
sequence makes more sense. :)
– Ped7g
Nov 23 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 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 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 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 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 at 13:01
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53432772%2fswap-columns-of-display-8086-assembly%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
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 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 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 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 at 17:17