Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created December 18, 2011 11:55
Show Gist options
  • Save ToJans/1493152 to your computer and use it in GitHub Desktop.
Save ToJans/1493152 to your computer and use it in GitHub Desktop.
Essay code samples
; com files are always loaded at 100h address
ORG 100h
start: ; make sure data segments and extra segments point
; to the same segment as the code, since this is a
; com app
MOV AX,CS
MOV DS,AX
MOV ES,AX
JMP readkey
invalidkey: ; print error message
MOV AH,9
MOV DX, errormessage
INT 21h
readkey: ; print inputmessage
MOV AH,9
MOV DX, inputmessage
INT 21h
; read key from keyboard, result is stored in AL
MOV AH,1
INT 21h
; if it is smaller then 'a' go to invalidkey label
CMP AL,'a'
JL invalidkey
; if it is larger then 'z' go to invalidkey label
CMP AL,'z'
JG invalidkey
; set lowerval in the output sting
MOV [lowerval],AL
; make AL uppercase
ADD AL,'A'-'a'
; set upperval in the output sting
MOV [upperval],AL
; print outputmessage
MOV AH,9
MOV DX, outputmessage
INT 21h
; Terminate app
INT 20h
inputmessage db 0Dh,0Ah,"Please enter a lowercase letter (a-z): $"
errormessage db 0Dh,0Ah,"Invalid input: this is not a lowercase letter!$"
outputmessage db 0Dh,0ah,"The uppercase of "
lowerval db 0
db " is "
upperval db 0,0Dh,0Ah,"$"
Program Essay;
uses SysUtils,Crt;
function ReadLowercaseLetter():char;
begin
while true do
begin
writeln('Please enter a lowercase letter (a-z):');
ReadLowercaseLetter := ReadKey;
if (ReadLowercaseLetter in ['a'..'z']) then
exit
else
writeln('Invalid input: this is not a lowercase letter!');
end;
end;
var
letter:char;
begin
letter := ReadLowercaseLetter();
writeln('The uppercase of '+letter+' is '+UpperCase(letter));
end.
using System;
namespace Essay
{
public class EssayConsole
{
char letter;
public void ReadLowercaseLetter()
{
while (true)
{
Console.WriteLine("Please enter a lowercase letter (a-z):");
var key = Console.ReadKey().KeyChar;
if (key >= 'a' && key <= 'z')
return;
else
Console.WriteLine("Invalid input: this is not a lowercase letter!");
}
}
public void WriteLastReadLetterAsUppercase()
{
Console.WriteLine("The uppercase of {0} is {1}",letter,letter+'A'-'a');
}
}
class Program
{
static void Main(string[] args)
{
var console = new EssayConsole();
console.ReadLowercaseLetter();
console.WriteLastReadLetterAsUppercase();
}
}
}
#light
open System
let ucase x = x.ToString().ToUpper()
let islowercase x = x >= 'a' && x <= 'z'
let rec getlcasechar _ =
printfn "Please enter a lowercase letter (a-z):"
let letter = (Console.ReadKey().KeyChar);
printfn""
if islowercase(letter) then
letter
else
printfn("Invalid input: this is not a lowercase letter!")
getlcasechar()
let lcasechar = getlcasechar()
printf "The uppercase of %c is %s" lcasechar (ucase lcasechar)
#light
open System
let ucase x = x.ToString().ToUpper()
let islowercase x = x >= 'a' && x <= 'z'
let rec getlcasechar _ =
printfn "Please enter a lowercase letter (a-z):"
let letter = (Console.ReadKey().KeyChar);
printfn""
if islowercase(letter) then
letter
else
printfn("Invalid input: this is not a lowercase letter!")
getlcasechar()
let lcasechar = getlcasechar()
printf "The uppercase of %c is %s" lcasechar (ucase lcasechar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment