cancel
Showing results for 
Search instead for 
Did you mean: 

Cygwin help

slider_1
Occasional Visitor

Cygwin help

well i am stuck on a problem involving cygwin. i am to create a program which is to
run from the command prompt. A buffer should be declared which will hold a character string of an appropriate length (say 80 characters). A menu of options is to be displayed indicating the choices shown below. The user can then enter an option letter between a-d inclusive. The option letter is processed as follows:

Option a - enter a string into buffer.
Option b - display string to the screen.
Option c - encode/decode string using rot13 algorithm.
Option d - program exits.

To read and write characters, you should only make use of the system calls getchar and putchar respectively. To perform the encoding/decoding you should make use of the rot13 subroutine supplied below.

rot13:
# ls byte of edx contains value to be en/decoded
# if char >= 0x41 && char <= 0x5a then uppercase
# if (char+13) > 0x5a then subtract 26
# if char >= 0x61 && char <= 0x7a then lowercase
# if (char+13) > 0x7a then subtract 26
#
cmpb dl, 0x41
jl r13l2
cmpb dl, 0x5a
ja r13l2
# uppercase
addb dl, 13
cmpb dl, 0x5a
jle r13l1
subb dl, 26
r13l1: jmp r13le
r13l2: cmpb dl, 0x61
jl r13le
cmpb dl, 0x7a
ja r13le
# lowercase
addb dl, 13
cmpb dl, 0x7a
jbe r13le # b not l, ignore sign bit!
subb dl, 26
r13le: ret



For assistance i have made a few templatles to start off with but am stuck on it. the templates are as follows:
1.
Template for IA-32 assembly language programs
# comments start with # in column 1
# commands which start with a . (dot) are assembler directives
# which do not generate machine code
.intel_syntax noprefix
.global _main

# put external (system) calls here
.extern _exit
.extern _getchar
.extern _putchar

.data
# declare variables here

.text
_main:
# main program code goes here ...

# for example, a program which adds the values in eax and ebx, stores
# sum in eax

mov eax, 3
mov ebx, 5
add eax, ebx

# programs always end with ...

mov eax, 0
call _exit


# user-defined subroutines(methods) go here ...

# end of program



2.
Program to write two strings, each separated by a newline
Without using user-defined subroutines

.data
s1: .byte 'm','e','s','s','a','g','e','A',0
s2: .byte 'm','e','s','s','a','g','e','B',0

.text
_main:

lea ebx, s1
wrstr1: # ebx contains string pointed to
mov al, [ebx] # get character
wh1:
cmp al, 0
je whe1 # jump if al == 0
whd1:
push ebx
push eax
call _putchar # display on screen
add esp, 4
pop ebx
inc ebx # ebx points to next char
mov al, [ebx] # get character
jmp wh1
whe1:
mov al, 10 # newline
push eax
call _putchar
add esp,4



lea ebx, s2

wrstr2: # ebx contains string pointed to
mov al, [ebx] # get character
wh2:
cmp al, 0
je whe2 # jump if al == 0
whd2:
push ebx
push eax
call _putchar # display on screen
add esp, 4
pop ebx
inc ebx # ebx points to next char
mov al, [ebx] # get character
jmp wh2
whe2:
mov al, 10 # newline
push eax
call _putchar
add esp,4


mov eax, 0 # exit
push eax
call _exit





3.
Example of input character routine
Pseudo code
declare data buffer

set pointer to (1st byte of) buffer
input a char
while not enter(LF) pressed do
store in buffer
increment pointer to next byte of buffer
input next char
end
add null char to define end of string



4.
Assembly language
.data
buffer1: .rept 80 # reserve 80 bytes in memory
.byte 0
.endr

.text
_main:
lea ebx, buffer1
push ebx
call _getchar # input char
# char returned in al
pop ebx

wh1:
cmp al, 0x0a # while not LF do
je end1 #
whd1:
movb [ebx], al # note movb (see note)
inc ebx
push ebx # point to next location
call _getchar # input char
# char returned in al
pop ebx
jmp wh1
end1:
movb [ebx], 0 # make string null terminated, movb again




So can anyone help me with this??
1 REPLY
Court Campbell
Honored Contributor

Re: Cygwin help

I am confused as to how this relates to help with cygwin. Looks as if you are asking for help with assembly.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"